Sign In/My Account | View Cart  
advertisement


Listen Print

The Lighter Side of CPAN
by Alex Gough | Pages: 1, 2

From One Date to Another

It is often said that computers and relationships don't mix well but this isn't entirely true. If you feel alone in the world and need to find that special person, then Perl is there to help you. Your first task is to meet someone. Perhaps by putting an advertisement on a dating service. Of course, you want to find the very best match and, being fond of concise notation, decide you will search for your companion with the help of the geek code. But how is your prospective mate to know what all those funny sigils mean? With the help of the Convert::GeekCode module of course:

 use Convert::GeekCode;

 print join("\n",geek_decode(<<'ENDCODE'),"\n");
 -----BEGIN GEEK CODE BLOCK-----
 GS d+ s:- a--a? C++> UB++ P++++ !L E+ W+++ N++ K? w--() !M PS++ PE+
 Y PGP+ t+(-) 5++ !X R+ !tv b+++  DI++ D+++ G e* h y?
 ------END GEEK CODE BLOCK------
 ENDCODE

Will tell you, amongst other things, that ``I don't write Perl, I speak it. Perl has superseded all other programming languages. I firmly believe that all programs can be reduced to a Perl one-liner.''

So, you've got a reply and someone wants to meet you. This is a worrying prospect though as you feel you'll need to brush up on your conversation skills a little before meeting your date. Again, Perl comes to your aid with Chatbot::Eliza, which is especially useful if you want to meet a simple-minded psychologist. Fire her up with:

 perl -MChatbot::Eliza -e'Chatbot::Eliza->new->command_interface'

and enjoy hours of elegant conversation:

 you:    I like pie
 Eliza:  That's quite interesting.

If your wit and repartee fail to impress, then you may want to convince your partner that you have a deep and lasting interest in some obscure branch of mystical poetry. Doing this requires some mastery of ZenPAN combined with a careful study of Lee Goddard's Poetry::Aum. More than any other module, this teaches you that true understanding comes from within: by inspecting the source of all your powers. The source code, that is.

If none of this works or you find you've arranged a date with a total bore, don't despair. There are ways to move the encounter toward an interesting conclusion. Simply let Michael Schwern's Bone::Easy take the pain out of dumping your burden.

 perl -MBone::Easy -le'print pickup()'

 When are you going to drain that?

How could all this be useful though? Convert::GeekCode hints at Perl's greatest strength: data transformation. The remaining 20 or so Convert::* modules can sometimes be a Godsend. If you are having trouble with EBCDIC-encoded text or need to make your product catalog acceptable to people who need whichever of metric and Imperial units you haven't provided, then you'll find something to furnish the answer.

Chatbot::Eliza on the other hand is a shining example of code whose behavior you can change easily. Because it was written using Perl's OO features and a bit of thought was applied while deconstructing the problem it addresses, it is full of hooks from which you can dangle your own bits of code, perhaps to use a different interface or a text to speech system. Can Bone::Easy teach you anything? Who knows ...

A Day at the Races

Having foolishly followed my dating advice above you will have a great deal of time to yourself but do not fear, you can still keep yourself amused. If you have a sporting bent, then Jos Boumans's ACME::Poe::Knee uses the wonderful POE framework to race ponies across your screen; you could even make bets with yourself sure in the knowledge that you'll end the day even. One day POE may fulfill its original purpose and morph into a multi-user dungeon (MUD), although at the moment, alas, it is far too busy being useful.

If you get tired of watching ACME::Poe::Knee, then you can instead follow Sean M Burke's Games::Worms, in combination with the cross-platform Tk Perl bindings, as it draws pretty patterns on your screen. Tk is only one of many graphical toolkits for Perl that can be used to quickly prototype an interface design or glue together a range of command line applications with a common frontend.

When Bugs Attack

Every now and then, despite all your best efforts to program extremely and extract the maximum of laziness from Perl, you will come across a deeply buried, complicated and fatal bug in your code. Your spirits sink when you discover one, the next two days of your precious time will be filled with cryptic error messages flashing all over your terminal:

 Something is very wrong at Desiato.pl line 22.

It needn't be like this though - there is a better way. You'll still have to fight this bug for days but you can keep your blood pressure at bay with a little application of Damian Conway's Coy. Simply add:

 PERL5OPT=-MCoy

to your environment (ideally somewhere global like /etc/.cshrc) so that any time Perl explodes all over your hard disk you'll be greeted by a soothing Haiku to take the edge off your pain:

        -----
        A woodpecker nesting 
        in a lemon tree. Ten 
        trout swim in a stream.
        -----
                Tor Kin Tun's commentary...

                Something is very wrong
                        (Analects of Desiato.pl: line 22.)

Setting PERL5OPT can help you in normal circumstances. Should you be developing an existing library you will often want to switch from the new to the old version, saying export PERL5OPT=-Ipath/to/new is less hassle than fiddling with use lib 'path/to/new' within your code.

These, along with a much larger host of useful modules, are available from the CPAN.