Perl Cookbook
When we switched from PH to LDAP, everyone else wanted to not support older e-mail readers. I grabbed the Perl Cookbook•, found the simple telnet server, and quickly modified it to gateway between PH and LDAP.
At first glance, this is a huge book, with lots of ‘recipes’ inside for programming in Perl. A lot of the recipes appear to be trivially obvious--whereby “trivial”, I mean that it would take less time to write the solution myself than to find it in a 750 page book. Others are not, however, and no doubt what I consider trivial others do not, and what authors Christiansen and Torkington consider trivial, I do not. This is a lot like the kind of answers you would get posting questions to the net, except that these are (hopefully) working examples rather than created off-the-cuff with “debugging opportunity provided as an exercise.”
Sometimes it’s weird seeing familiar names in unfamiliar places. I remember Tom Christiansen• from my Dungeons & Dragons days. He was one of the early crew at TSR and lived next door to Gary Gygax. He (as did I and probably a whole generation of coders) did some of his earliest programming writing character generation tools for role-playing games.
There is not, unfortunately, any of that in “Perl Cookbook”. There is just about everything else, however. I just opened it randomly to page 218, and found the “Regular Expression Grabbag”. Regular expressions for grabbing Roman numerals, grabbing dates and times, grabbing links from HTML. One of the sections I use most often is the sockets section, chapter 17. There’s “Writing a TCP Client” which implements a simple means of connecting to TCP/IP servers, and “Writing a TCP Server”, which implements a simple means of waiting for clients to connect over TCP/IP.
There is a small chapter on CGI programming, which includes recommendations to use the CGI module. But many of your CGI problems will have solutions in more specific areas. Browsing through the book (and if you’re a real Perl programmer, you’ll probably browse through this book simply for the fun of reading it; it makes better bathroom reading than most) I see in “Numbers” a recipe for generating weighted random numbers, for example “to randomly select a banner to display on a web page, given a set of relative weights saying how often each banner is to be displayed.”
There are sections on using TK to provide a more robust user interface, object-oriented programming in Perl, strings, numbers, dates and times (the same thing in Unix), arrays, hashes, pattern matching, file and directory access, subroutines, packages, databases, process management, sockets, and even web automation (automating access or updates to web pages). It provides a useful index for finding the solutions in these sections. (Just glancing through for this review, I discovered something to do with Expect in Perl, which could ease some problems I’ve been having using Expect in CGI programming.)
Something that would have been useful, which I don’t see, would be instructions on the use of CPAN to grab modules, since often the solutions presented here require or at least recommend the use of one or more non-standard modules. There’s a tiny section on installing modules that you’ve already downloaded, but nothing that I can find about using the command-line CPAN interface to more easily install them from scratch. (In their favor, it may be that when this book was published in late 1998, the CPAN interface had not yet been standardized.)
“Perl Cookbook” was created as a companion to the “Programming Perl” reference and tutorial (“the camel book”). The first edition of that book had chapters on “Common Tasks” and “Real Perl Programs”. Those chapters were removed from the revised camel due to space considerations. This is a monster expansion of those original two chapters. This means that it includes some incredibly simple “common tasks” as well as some more complex “real programs”.
If you use Perl regularly, you’ll probably find this useful. This is one of a rare breed of books that I purchase two copies for, one for the office and one for home. It was developed using Perl 5.004_04, so the examples will work best with that version or later.
- Nathan Torkington
- Loves Perl. Programs Perl. Writes Perl books. Edits Perl magazines. Organizes Perl conferences.
- Perl Cookbook•: Tom Christiansen and Nathan Torkington
- This is probably the most useful Perl book I own. Whenever I need a solution quickly—which is often here at the University—I am very likely to find my start in the Perl Cookbook.
More Perl
- Simple .ics iCalendar file creator
- A simple Perl script to create an ics file from a human-readable text of events.
- No premature optimization
- Don’t optimize code before it needs optimization or you’re likely to create unoptimized code.
- Using Term::ANSIColor with GeekTool
- Rather than using the raw codes directly, Perl (at least on OS X) comes with Term::ANSIColor built in.
- Nisus HTML conversion
- New features in Nisus’s scripting language make HTML conversion almost a breeze.
- Nisus “clean HTML” macro
- The Nisus macro language is Perl; this means we can use all of Perl’s strengths as a text filter scripting language in Nisus.
- Three more pages with the topic Perl, and other related pages
More programming books
- 42 Astoundingly Useful Scripts and Automations for the Macintosh
- MacOS uses Perl, Python, AppleScript, and Automator and you can write scripts in all of these. Build a talking alarm. Roll dice. Preflight your social media comments. Play music and create ASCII art. Get your retro on and bring your Macintosh into the world of tomorrow with 42 Astoundingly Useful Scripts and Automations for the Macintosh!
- Learning Python
- If you’ve been looking to learn Python, or need a new language with clearly defined scope and easy objects, this is an extremely useful book.
- AppleScript: The Definitive Guide
- AppleScript is an extremely useful tool for automating the repetitive things you do in Mac OS X applications, as well as for tying a long workflow together into a double-clickable icon. This Definitive Guide is a great reference for the AppleScript scripting language.
- Webmaster in a Nutshell
- Without doubt the best reference work for webmasters that you’ll find. It contains the “reference” part of most of O’Reilly’s web-relevant nutshell books. You can find references for HTML 3.2, the CGI standard, JavaScript, Cascading Style Sheets, PHP, the HTTP 1.1 protocol, and configuration statements and server-side includes for the Apache/NCSA webservers.
- HTML & XHTML: The Definitive Guide
- I’ve never found an HTML book that I’ve considered great. This one is probably the best. It covers just about everything in HTML, as well as a little bit of Cascading Style Sheets.
- One more page with the topic programming books, and other related pages