Perl Poetry: A Code Haiku Collection
Everyone has seen the Perl ASCII art and obfuscation competitions that are everywhere. I’ll make my own attempt, with a Perl haiku collection. These four haikus form a syntactically correct script that prints all prime numbers lower than 100.
my @primes = (2); my $limit = 100; my $i = 2; my $b = 0; while ($i < $limit) { $i += 1; foreach $_ (@primes) { unless (!($i % $_)) { } else { $b = 1; } } if ($b == 0) { push @primes, $i; } $b = 0; } print "@primes \\n";
Pronounce the code like this:
My primes equals two
My limit equals hundred
My i equals twoMy b equals o
While i is less than limit
I plus equals oneFor each under primes
Unless not i mod under
Else b equals oneif b equals o
Push primes i, b equals o
Print primes backslash n
It works perfectly, too.

Alas it was true
people do write code haikus
too much time on hands
nice script BTW :-)
Comment by Iv — January 21, 2007 @ 8:29 pm
Ib, thanks. Nice Haiku. :)
Comment by Tim — January 22, 2007 @ 6:27 am