07 November 2005
This post may be outdated due to it was written on 2005. The links may be broken. The code may be not working anymore. Leave comments if needed.
在我的 journal Index 页上往下数四行,会出现 Larry Wall 的一些语言。本来就一句
Call me bored, but don't call me boring. -- Larry Wall
后来想想应该多增加一点,且变成随机出现。一想到随机,我第一个想到的就是 List::Util , 那里面有个 shuffle 函数用以打乱 list 的次序。
当然这不是唯一选择,或许也不是最好的选择。不过或许也算凑巧, CPAN 上还是有它的 Template Plugin: Template::Plugin::ListUtil

放到里面的代码很简单,大致就是:

[% USE ListUtil %]

<style>
.quotes {
   white-space: -moz-pre-wrap; /* Mozilla, supported since 1999 */
   white-space: -pre-wrap; /* Opera 4 - 6 */
   white-space: -o-pre-wrap; /* Opera 7 */
   white-space: pre-wrap; /* CSS3 - Text module (Candidate Recommendation)
http://www.w3.org/TR/css3-text/#white-space */
   word-wrap: break-word; /* IE 5.5+ */
}
</style>

[% quote_words = [
"Call me bored, but don't call me boring. -- Larry Wall",
"I don't know if it's what you want, but it's what you get. :-)
-- Larry Wall in <[email protected]>",
"I think it's a new feature. Don't tell anyone it was an accident. :-)
-- Larry Wall on s/foo/bar/eieio in <[email protected]>",
"Obviously I was either onto something, or on something. -- Larry Wall",
"The following two statements are usually both true:
There's not enough documentation.
There's too much documentation. -- Larry Wall",
"If someone stinks, view it as a reason to help them, not a reason to avoid them. -- Larry Wall",
"In general, if you think something isn't in Perl, try it out, because it usually is. :-)
--Larry Wall in <[email protected]>"
] %]

<div class='quotes'>[% ListUtil.random(quote_words) %]</div>

后来又把右边浮动框的颜色也随机化了一下。

大致也就这样。看了一点 Perl Template Toolkit 的 Chapter 5. Filters



blog comments powered by Disqus