![]() ![]() ![]() ![]() |
Minimal Perl: For UNIX and Linux People
by Tim Maher
Manning Publications 2006*
ISBN 1932394508
Reviewed by Peter Scott
Somewhere in the jungle of small niche markets, between the COBOL object-oriented design pattern architects and the Ada game developers, lies the neglected category of Unix Shell Programmers. They get so little attention you might think them nonexistent. Yet surely vast numbers of Perl programmers are in fact refugees from the shell, which is one of the top design influences on Perl. It would make sense to smooth the way for them, would it not? So finally, Tim Maher, Seattle Perl User Group founder and Perl/Unix trainer, fills the gap by showing shell programmers how their favorite tasks go better with Perl.
The first half is occupied with showing how to use Perl instead of sed, awk, grep, and find; the second half with the basic syntax, built-ins, and data types of Perl. Numerous lengthy examples populate both sections. In fact, everything about this book is big, from its table-straining 505 pages and enormous section on typographical conventions to the addition of the history of the people on Manning book covers.
Its central thesis is that a little Perl goes a long way: that you can get your job done with only a fraction of Perl's capabilities. It makes the analogy of a Dutchman moving to Switzerland needing to learn only German to get by, instead of the languages used there that are less like Dutch. In fact, this may be the longest book to teach Perl that never goes as far as references: the furthest it gets is showing how to use Exporter to make a subroutine library. It's halfway through before it shows the if statement and even later before it introduces arrays. So what is it doing before then?
Answer: Minimal Perl starts out with cat-like filters and exploring the command-line flags of perl. This novel approach digs into perlrun to show how to construct numerous useful programs without even having to open an editor; it's the ultimate homage to the one-liner. When it does start showing actual shebang lines virtually every one of them is adorned with options you would expect only in a one-liner, such as -l -n, -0, and -p. If you want to know about Perl's paragraph mode, this is the place to come. And never have I seen so much coverage (okay: any coverage) of the -s flag. (Don't know what that one does? It's a sort of poor man's Getopt::Long.) More unique value: listing useful clusters of options so you don't have to learn the rules of how they should be ordered.
This book sets a new standard in chattiness. A style that would be excellent in a classroom might grate on a reader who has a low tolerance for cute neologisms like "JAPHly", "stoogeadelic", "grepology", and "perlocity" peppering the text, "PerlDude" rescuing "WinDude", or idioms like "Shazaam" and comic-book-like use of italics. Minimal Perl knows no idiomatic top over which it will not go. Some of the recommended practices are controversial, like using <> instead of glob(), and avoiding object-oriented CPAN modules where possible. This is nitpicking in the general Perl book market, but you're not going to find a technical error in a book by Tim - the closest I found was a footnote that a script scraping a site at 'usatomorrow.com' "worked at press time" when it doesn't; but when I tried 'usatoday.com' instead, that worked.
Little items I found of special value: Coverage of the author's Shell::POSIX::Select; the -text option of lwp-request; the advice to put the main program in a naked block of its own; the comparisons between classic, POSIX, GNU versions of utilities and Perl; and using -i. $SECONDS on the command line to avoid clobbering your only backup. That last example is one of many in this book of a synergy between Perl and the shell that you will not find elsewhere. Beginners will find the graphical illustrations of scoping handy, but I disagree with the decision to leave out use strict until near the end. Bottom line: shell veterans will find an easy bridge to Perl that speaks to them in their own language; shell neophytes will find a tour de force road map for getting useful stuff done.
* This book appeared to be published around September 2006. Yet Amazon claims it came out September 2005, and the PDF I reviewed claimed a copyright of 2007.Take your pick.