I have a rather strange relationship with the programming language perl. I've never used it for doing anything beyond quick and dirty scripts, and even then, I haven't done much with those. On the other hand, the regular expression engine built into perl makes it ideal to do obfuscated programming, and I've done a number of those. Most of these have been created with David Chan, who's more ept at perl programming than I, with me taking on more of the algorithms side, and he taking more of the programming side.
Our first program was intended to be an entry into The Perl Journal's obfuscated perl contest (which was unfortunately shut down before we could submit it).#!/usr/bin/perl -w
The program, called "The_Perl_Journal", prints "The Perl Journal", using interprocess communication, and semaphores. Just like gzip, it behaves differently depending on what its name is; try creating symlinks/copies called "sink" and "swim".
In case you can't work out what it does, there are hints, and solution1 and solution2.
Continuing the theme set by the above program, we continued into similar areas...perl -ple'(/[^.-\s]/)?(s.[^a-z0-9\s].$_=unpack"B*",$&;y;01;\n`;;lc.ge,y.
Alas, the program didn't quite manage to fit it into signature size, as the comment at the end shows. On the other hand, it does have the ability to handle non-standard characters and to autodetect what conversion it's supposed to be performing. Why not give it a spin?
The next program we created was a perl implementation of Tetris, in under 640 bytes. You use the arrow keys to control the pieces, and space to drop them. It comes complete with higher score for scoring multiple lines and the ability to move your piece after you've dropped it using space.#!/usr/bin/perl
Unfortunately, the program comes up with a warning when run under -w, which we were unable to prevent due to space constraints, so it's being run without -w instead.
This program is somewhat harder than the others to decode - to help you, the key logic is in the for loop in line 6, which picks up the input to control the pieces using sysread in line 7. This calls subroutines j (which prints the screen) and n (which generates a new piece). The data structures in subroutine n contain the position data for the pieces in all rotated states - we don't try to rotate them on the fly.
One thing that I learnt when creating these programs was that the key part of any program was working out the correct data structure to encode the data in as minimalist a way as possible, and the next most important part was working out how to handle the data structure to get it to the state that you wanted it to be in. When creating a version of sokoban, David got around the first problem by using the level data from xsok. I thought this was cheating, and by dint of some creative hacking, created the following .sig sized version.#!/usr/bin/perl -w
The program contains a level which is pleasingly non-trivial given its size - a number of people have got stuck the first time the tried it.
If you have any questions or comments about these programs (or ideas about how to make them smaller / more featurefull), then do feel free to contact me - I'd be interested to hear what you have to say.