The Obfuscated Perl Contest

By Deane Barker on December 24, 2004

There’s a fascinating contest afoot since 1996 called “The Obfuscated Perl Contest.” The idea is to write the most needlessly complex Perl program your evil little mind can think up.

According to the Wikipedia page, there are four categories which tend to limit the size of the programs to just 1 or 2K. Here’s a good overview of the categories and rules.

I couldn’t find an actual home page for the contest, but since one of the categories requires entrants to print out “The Perl Journal,” that magazine probably has something to do with it. I did find a number of associated links that showed me far, far more than I wanted to know.

This guy won 2nd place. To give you an idea of how wretched these programs truly are, here’s a small piece of his explanation:

The program forks thirty-two copies of itself. Each copy is responsible for printing exactly one character from @data. Because the 32 processes are running concurrently, they somehow need to synchronize themselves so that the thirty-two characters come out in the right order. They use two mechanisms to accomplish this: First, parents wait for their children to complete before printing and exiting. Second, the processes use pipes to communicate to one another when they are finished. About half the program logic is concerned with the details of setting up the pipes correctly.

His program was just 332 characters long. I never did figure out what exactly it printed out.

This guy also won second place (I couldn’t figure out what year), but doing something even more ridiuclous: he combines two programs, then hid a subroutine to split the “true” code out and eval it.

I took half of the top portion of the code and half of the lower portion and then interlaced the characters of each. I added a for loop to the final code that separated the two halves, concatenated them, then called eval() to interpret the original program.

Now, I don’t know if that’s cheating or not, since he’s doing things that serve no purpose other than to make things difficult. I would think that extra points would be given to techniques that had an actual purpose separate from the contest itself.

I really liked this guy (man, “this guy” is apparently one hell of a Perl programmer…), who also used the “extracted string which is eval’d” technique, but which resulted in an ASCII clock which displays the current time. Very nice, and perhaps even useful.

From the Wikipedia page, I found this related page about the apparent joy of writing Perl programs to print out “Just Another Perl Hacker”. There are some examples there that are very intriguing, including the last one which appears to be nothing more the a block of Perl keywords. How that might work, I haven’t the first clue.

Maybe they should talk to the guy who writes Perl in latin. Wouldn’t that be obfuscated enough? Or how about the wicked soul that wrote the definitie guide on How to Write Unmaintainable Code? There are some techniques in there that would be worth exploring.

In the end, I can’t disagree with this post to a Perl list-serv. When confronted with the title “Obfuscated Perl Contest,” this poster responded:

isn’t this an oxymoron?

I’m with him.



Comments are closed. If you have something you really want to say, tweet @gadgetopia.