Third Annual Obfuscated Perl Contest
Best "The Perl Journal"
Dave Methvin
dm1024@methvin.com.

In the BEGIN block, the first map function stuffs two kinds of items into the package's symbol table. The first are the names of some subs used in the poetry: think, disarray, perilous, imperiled, empowered. Second are fragments of code used in the eval; these mostly look like "map(", "print(", "substr(", and so on.  The literal strings stuffed into the symbol table are obfuscated by transliteration of characters.

The next map function builds %t, its keys are a simple numeric hash function of all the strings in the package symbol table. All the values I want have two-digit keys. Those values are substituted into the $_ string and then evaled. 

The evaled string is an AUTOLOAD last-chance handler for the poetry functions. The AUTOLOAD function is easiest to explain by example: 

disarray recedes_now, as_light_dawns;
  $AUTOLOAD = TPJ::disarray
  length("recedes_now") = 
    11th char in $AUTOLOAD ("a")
  length("as_light_dawns") = 
    14th char in "The Perl Journal" ("a" in Journal)

These value pairs (character, chr(destination index)) are pushed into the $perl list reference. 

Exception: Two functions called with $perl are used to insert the spaces between words. The length of the name of the function, not counting "TPJ::", indicates where the space goes in the string.

Bug: because it uses the length of the result of the time() function, this code will not print the correct string after September 8, 2001 around 10pm, when the time becomes a 10-digit number. But I kind of like that. Code this wierd shouldn't work forever.

When the program exits, Perl calls TPJ::DESTROY with the blessed $perl list. The AUTOLOAD function detects the situation by checking the length of the function name, and prints the string in the right order by sorting the $perl list. 

The biggest challenge I had was to be able to write the poetry and have enough of the 1024 bytes left to do any sort of obfuscation. I can now think of about a half-dozen ways to make it smaller and more obfuscated, but I guess I have to save those for next year.