Saturday, March 18, 2006

It can be a refreshing tonic of a language when you move to perlfrom something like basic, C or Java.Perl can do what tens of Unix tools such as sed and awk can do fromthe shell, but with more flexibility and higher order data structuressuch as the perl 'hash' or 'associative array'.You can sit and evolve a perl one-liner of X hundred charactersthat will find and process millions of lines from thousands of filesfrom within hundreds of directories.When you want to know how to do something else there is The Camel, either the book or that human store of Perl Knowledge on the nextfloor, a few cubicles over.Before long, you have amassed a large personal perl knowledgebase, and can tackle most of your tasks, without having to consultThe Camel. You become more confident in perl and start to code forothers in your team, and write scripts in files rather than oneliners.

WAKE UP!

Languages have moved on.

Do you use perl references? Happy with them? Do you know that youcan get all that power without all the reference-gymnastics. Indeed,you can get more power as you are freed from the mundane “howdo I create and use a hash of hashes”, to “O.K. The datanaturally starts as a hash of hashes so...”

Perl subroutines. Even AWK, one of the Unix stalwart languagesthat perl was created to supplant has named arguments to itsfunctions. The better scripting languages can do a lot better,allowing you to pass two lists into a function as easily as passingin two integers. Or to return three hashes just as simply.

The perl slogan “There is more than one way to do it”is often cited as one of perls strengths, and used by manyperl-mongers as their reason to stick with it. But how many of youactually mean the extended form: “There is more than one way todo it, and mine is the best”, or, “There is more than oneway to do it, but you will use mine!”, or more likely: “Thereis more than one way to do it, and I don't know yours”, or“There is more than one way to do it, and you will learnmine!”, or “There is more than one way to do it, but Idon't know how to find any of them in Camels index”.

Perl still has goto! (and in its most evil of forms too, thecomputed goto: where you have to interpret the program in your headto work out where the goto might jump to from the listing because thegoto target is the result of an expression).

So much of perl documentation reads like 1001 recipes for using1001 features, without any central theme to shape them.

Being an engineer, I am trained in finding patterns andextrapolation. It is much easier for me to learn a small set ofpowerful rules with a straightforward way of combining them. Perl,unfortunately has a large number of 'gotchas' that bite when you tryto venture out from the recipes and examples given.

Conclusion

If you know perl, and have a need for programs greater than a fewtens of lines of code, then you should invest a week or two of yourtime learning a different dynamic language. In that time, put asideyour perl knowledge and try to not just use the other languagessyntax, but learn how things are naturally done in that language.Nothing may beat the 'perl -p -i -e' one-liner, but proper functionparameters and strict typing may be better for your longer scripts.

If you are thinking of learning Perl then think twice. Perls'sweat-spot' is much diminished as new dynamic languages have emergedwith a less tacky support for new methodologies and standards such asobject oriented programming, program maintenance, functionalprogramming, XML, multi-language programming, and programming onmultiple frameworks such as dot-net and the Java Virtual Machine.