Slashdot Mirror


The Perl Cookbook, 2nd Edition

doom writes "For those of you who haven't been paying attention, when the The Perl Cookbook by Tom Christiansen & Nathan Torkington came out in 1999 it immediately became one of the primary references in the perl world. It's one of the first places you should check before making a move with perl, right up there with search.cpan.org, itself. Now we've got the second edition. What's the diff? The diff is 58 new recipes and program examples (list provided below), plus two new chapters on mod_perl and XML (which provide an additional 27)." Read on for doom's complete review. The Perl Cookbook, 2nd Edition author Tom Christiansen & Nathan Torkington pages 927 publisher O' Reilly rating 9 reviewer doom ISBN 0596003137 summary How to do common tasks in perl

The new recipes cover a number of subjects. One of the prominent themes is how to use perl's new unicode support, as well as the new I/O layers feature. The coverage of web programming has definitely been fleshed out with recipes on XML-RPC, SOAP and so on, plus the new chapter on mod_perl. Also of interest of course are the additional recipes on database access with DBI.

The mod_perl chapter is a good succinct introduction, with some very cute recipes in it (though admittedly a lot of these are also covered in the excellent Mod_perl Developer's Cookbook by Young, Lindner and Kobes out from Sams). For example "Transparently Storing Information in URLs" shows how to embed information in any arbitrary position inside a URL. This quickly shows the kind of things you can do with a PerlTransHandler and a PerlFixupHandler. The chapter closes with what looks like a good introduction to "Template Toolkit", which I would probably be very excited about if I wasn't already familiar with the (also discussed) HTML::Mason.

I really enjoyed reading the XML chapter (a subject I'm less familiar with): I predict that you'll find this to be the fastest way through the XALPHABET XSOUP without drowning. For me, this was almost worth the price of the book.

Very little has been removed (hence the page count has gone from 757 to 927), and where I have been able to find a deletion, there are usually very good reasons for it. For example, the first edition takes the trouble to tell us that qr// was introduced in perl 5.005, but the new edition drops the babble about versions there, because for most of us, anything before 5.6 is now ancient history. However, I do miss this particular irrelevant parenthetic aside that's been deleted now:

Remember that the opposite of read is not write but print, although oddly enough, the opposite of sysread actually is syswrite. (split and join are opposites, but there's no speak to match listen, no resurrect for kill, and no curse for bless.)
(p.295, first edition, compare to p.323, second edition.)

In general, it's difficult to think of anything seriously wrong with the Perl Cookbook. I might suggest that in some places they fall into the trap of talking about all the ways to do it, rather than just the best ways, (e.g. recipe 7.5 "Storing Filehandles into Variables" seems a bit complicated).

And maybe there are some slight problems with order of presentation, as with the new perl 5.8 feature of "I/O Layers", which is mentioned a few times before it's finally discussed in the beginning of Chapter 8 (though really, it's amazing that there aren't more problems like this: this is supposed to be reference work, and yet it usually works well as a tutorial also).

I've got one big complaint about the 2nd edition though: they changed the numbering of existing recipes! I've been writing code with comments like

# Schwartzian transform. See Perl Cookbook, recipe 4.15
and now it turns out I should've been specifying an edition number also. Please: "Cookbook" authors, come up with a numbering scheme that remains invariant with new editions... if you can't always just append to the end of the chapter, there's nothing wrong with tacking another dotted decimal on the end. We're programmers, we can handle it.

And speaking of the "Schwartzian transform" that recipe has a very clear, self-explanatory name "Sorting a List by Computable Field", but in the first edition, there was also a footnote explaining that many people call this the Schwartzian Transform, named after Randall Schwartz, who invented the technique. With this second edition, that footnote has been quietly dropped. Guys, if you're going to carry on a feud, this is really not the way to do it. It just makes you look bad.

O'Reilly's perl.com site has a series of articles by the authors, featuring some recipes from the book:

Appendix: New recipes and examples (not including the two new chapters):

  • Using Named Unicode Characters
  • Treating Unicode Combined Characters as Single Characters
  • Canonicalizing Strings with Unicode Combined Characters
  • Treating a Unicode String as Octets
  • Properly Capitalizing a Title or Headline
  • Constant Variables
  • Implementing a Sparse Array
  • Creating a Hash with Immutable Keys or Values
  • Matching Nested Patterns
  • Writing a Subroutine That Takes Filehandles as Built-ins Do
  • Storing Multiple Files in the DATA Area
  • Reading an Entire Line Without Blocking
  • Treating a File as an Array
  • Setting the Default I/O Layers
  • Reading or Writing Unicode from a Filehandle
  • Converting Microsoft Text Files into Unicode
  • Comparing the Contents of Two Files
  • Pretending a String Is a File
  • Working with Symbolic File Permissions Instead of Octal Values
  • Writing a Switch Statement
  • Coping with Circular Data Structures Using Weak References
  • Program: Outlines
  • Overriding a Built-in Function in All Packages
  • Customizing Warnings
  • Writing Extensions in C with Inline::C
  • Cloning Constructors
  • Copy Constructors
  • Saving Query Results to Excel or CSV
  • Escaping Quotes
  • Dealing with Database Errors
  • Repeating Queries Efficiently
  • Building Queries Programmatically
  • Finding the Number of Rows Returned by a Query
  • Using Transactions
  • Viewing Data One Page at a Time
  • Querying a CSV File with SQL
  • Using SQL Without a Database Server
  • Graphing Data
  • Thumbnailing Images
  • Adding Text to an Image
  • Program: graphbox
  • Turning Signals into Fatal Errors
  • Multitasking Server with Threads
  • Writing a Multitasking Server with POE
  • Accessing an LDAP Server
  • Sending Attachments in Mail
  • Extracting Attachments from Mail
  • Writing an XML-RPC Server
  • Writing an XML-RPC Client
  • Writing a SOAP Server
  • Writing a SOAP Client
  • Program: rfrm
  • Using Cookies
  • Fetching Password-Protected Pages
  • Fetching https:// Web Pages
  • Resuming an HTTP GET
  • Parsing HTML
  • Extracting Table Data

You can purchase The Perl Cookbook, 2nd Edition from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

5 of 148 comments (clear)

  1. Christiansen on /. by craw · · Score: 1, Offtopic

    FYI. Tom Christiansen (54829) used to post comments here. He stopped because of the crap associated with the story on the death of Richard Stevens. Search for Christiansen to read his parting words.

    IIRC, then came karma.

    1. Re:Christiansen on /. by Camel+Pilot · · Score: 0, Offtopic

      Yes Tom's post is worth reading again. I have several of Stevens (and Tom's including the aforementioned) books sitting on my shelf. It is too bad that the moderation system does not do a better job of filtering out the stupid, immature and souless comments more efficiently.

    2. Re:Christiansen on /. by kisrael · · Score: 0, Offtopic

      Interesting. I hadn't heard much about W. Richard Stevens before then...and it's funny, the negative comments were modded down to hell, just leaving a lot of people pointing out the ignorance and unseemliness of the negative comments. Seemed like a strong case of "a few bad apples".

      Actually, I'm always a little amazed that any "big names" show up here, and then I'm amazed that I find that amazing.

      Feh, I wish I had gotten my username here when I started reating, instead of a year or two after. I'd have an even lower # then ;-)

      --
      SO YOU'RE GOING TO DIE: The Comic for Dealing with Death
  2. Before my time... by The+Ape+With+No+Name · · Score: 1, Offtopic

    ....But I can personally attest that Christiansen can be such a jerk that he can't even be approached when he is positively wrong. I pointed out a very specific bug in Perl back in the Perl 4 days which had not been fixed for weeks to him. He said it had been fixed and that I was a fuckwit for bringing it up again. Gave him code to show I could still do it. He called me a liar. I appealed to higher gods. He caught wind. Then started a campaign to squash me on comp.lang.perl.misc. That worked because of his unfailing followers. His parting shot to me was some shit about being more educated than me (seemed very proud to be able to speak a couple of languages other than English. This is an accomplishment for an American, I admit) and making money at Perl. Blah. Blah. I seriously thought this was someone spoofing the guy for the longest time, because when I met him at conference before this period, he was very forthright and pleasant. Actually, he seemed like a nice guy to hang with or maybe work for. Anyhow, I gave it a rest. Perl is just a fucking programming language. Linux is just an OS. I understand he has disappeared from USENET as well because of abuse from users, his unabiding dislike of Newbies, and lack of time in general. Anyhoodles, all programming languages and OSes suck. Some just suck less. Perl is one that sucks less. Linux is one that sucks less. Hrmph.

    --
    Comparing it to Windows will be a moot point, since El Dorado is going to have a 40% larger code base than XP.
  3. a feud would be double-sided by merlyn · · Score: 0, Offtopic
    Guys, if you're going to carry on a feud, this is really not the way to do it. It just makes you look bad.
    Please, let's be clear. This little spat that Tom has about me is completely one-sided. I get a bit pissy when I have to play defense, but otherwise, it's entirely about Tom attacking me. I have nothing against him otherwise.