Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
News Books Media Book Reviews

Review:The Perl Cookbook 65

The critical companion to the Camel/Llama books, the Ram book, published by O'Reilly, Perl Cookbook: Solutions and Examples for Perl Programmers has been reviewed by Reviewed by: Eugene Sotirescu. This piece of art has been written by Tom Christiansen and Nathan Torkington-and if you want the scoop on the book, click below.
Perl Cookbook: Solutions and Examples for Perl Programmers
author Tom Christiansen and Nathan Torkington
pages
publisher O'Reilly & Associates
rating 10
reviewer Eugenia Sotirescu
ISBN
summary An indispensable compendium of Perl programming problems with expert solutions and commentary.

The Scenario

The first Perl book, "Programming Perl", (Larry Wall and Randal Schwartz, 1990; aka the Red Camel) included 2 chapters, "Common Tasks with Perl" and "Real Perl Programs", that were left out of the second edition of the book ("Programming Perl", by Wall, Tom Christiansen and Schwartz, 1996; aka the Blue Camel). Many people bemoaned the omission of all these Perl-at-work gems and one of the authors, Tom Christiansen, undertook to expand the 2 orphan chapters into a separate book. Two years later, with the help of fellow Perl programmer and Perl FAQ maintainer, Nathan Torkington, Christiansen gave us the "Perl Cookbook" (aka the Ram book).

While no review can even get close to summarizing the wealth of information in this book, its structure is easily described: the organizing metaphor is the cookbook and therefore the bulk of each chapter contains recipes designed to address specific programming problems.

A Code Feast

Here's a brief list of other goodies you can find in this book:

  • a juicy regex grabbag, that shows how to match HTML links, IP addresses, all-caps words and key=value pairs among many other patterns.
  • A full chapter on Database access that in addition to DBI also includes the most extensive discussion of DBM files in Perl literature.
  • 40 pages on UNIX processes from the point of view of Perl.
  • Examples on how to write demon and non-forking servers in the chapter on sockets and code to create robots, parsing server logs and automating form submission in the chapter on web automation.
  • Numerous tips and examples of safe and efficient CGI programming in the chapter devoted to this.
  • How to keep your modules separate from the system-wide ones and how to prepare modules you've written for CPAN distro
  • Everything you ever wanted to do to dates/time but didn't quite know how .

At times, though, the authors can't keep themselves to just code snippets and cook a full ready-to-eat meal in the form of a complete program to cap the solutions presented in a chapter.
At the end of the Pattern Matching chapter, for example, you can find 'tcgrep', Tom Christiansen's cross-platform supergrep that "ignores anything not a plain text file, automatically expands compressed or gzipped files, recurses down directories, searches complete paragraphs or user-defined records . . . and adds underlining or highlighting of the matches". A program called 'hopdelta' caps the "Dates and Times" chapter and shows the time an email message took to reach each destination based on an analysis of its header.

Anatomy of a Chapter

After an introduction that tries to present the history and general outline of the topic of the chapter come the numbered recipes. Each recipe is divided into 4 parts: a brief statement of the Problem, followed by the code of the Solution and a detailed Discussion with further comments, code examples and pitfalls. The recipe ends with a See Also paragraph that sends the reader to the relevant man pages and further references.

Chapter 7, for instance, deals with File Access. It opens with a 4-page discussion of the basic concepts of file handles and I/O. It then quickly moves into the recipes, which range from the basic (opening a file, covered in depth, output flushing) to the often used and asked about (writing a filter, modifying a file) and ends with a longish complete program that implements lock control over a designated region of a file. Changing a file has 3 sections devoted to it: in-place modification using a temp file, doing it from the command line and the less common in-place modification without a temp file.

(Note: if you've been modelling your file locking on the flock() example on pp.166-7 of the Camel book, make sure you check out recipe 7.11, "Locking a File", to see what you may be doing wrong).

What's Bad?

I'd say: nothing. A caveat is in order, though.
Good recipes do not a gourmet cook make. A handy compendium of code snippets like the ones in this book will help solve the problem at hand, but won't help you design better programs. I don't mean to detract from the book's value (after all its purpose is not to teach program structure), just to deflate a little the beginning Perl programmer who uses this book to get unstuck: he's solved the problem at hand and that's great, but he's not necessarily a better programmer for it. The authors are probably aware of this, hence the complete programs at the end of the chapters. I only wish there were more of these.

What's Good?

Lucid presentation and clear organization make this book not only useful to refer to, but also pleasant to read through. And the code in it comes not only from experienced authors, but has also been polished by the feedback from scores of Perl gurus, which is a pretty good guarantee of its quality.

Do YOU Need the Ram book?

To make it short, let's actually ask: "who doesn't need the Ram book?"
If you're Larry Wall, you probably don't need it . That's it. For the rest of the Perl crowd this book is pretty much an essential companion to the Camel, as both resource and learning tool.

(Note: If you use Perl to teach yourself programming, use the Llama ("Learning Perl," by Randal Schwartz) to get going, but keep the Ram in mind: if you get anywhere with Perl you too will want it).

Buy this book here.

Errata

Table of Contents

  1. Strings
  2. Numbers
  3. Dates and Times
  4. Arrays
  5. Hashes
  6. Pattern Matching
  7. File Access
  8. File Contents
  9. Directories
  10. Subroutines
  11. References and Records
  12. Packages, Libraries, and Modules
  13. Classes, Objects, and Ties
  14. Database Access
  15. User Interfaces
  16. Process Management and Communication
  17. Sockets
  18. Internet Services
  19. CGI Programming
  20. Web Automation
This discussion has been archived. No new comments can be posted.

Review:The Perl Cookbook

Comments Filter:
  • by Anonymous Coward
    I saw this cookbook in the bookstore. It's good, but I passed because Chp 19 didn't quite have as much as I would like.

    Meanwhile, their web CGI book is a few years old and goes all over the place with Perl, VBscript and Mac stuff.

    I'd like to see ORA maybe combine the talents of Shishir, Matt Wright, and Selena Sol in one book.
  • Well, we could simply shut-down the site. Servers and bandwidth don't materialize out of the air. If you think we're making money on here, I don't think you realize how mistaken you are. Rob earns 1/2 minimum wage, me 1/10. Authors nothing.
  • yeah, it's a nice book and I looked up some stuff more than once. But is it as essential as the Camel? By no means. It's like a very elaborate FAQ, tasks that have to be done often and stuff ppl do wrong a lot. In this respect it's a good read for Perl-newbies(not neccessarily programming newbies). Once you passed the initial hurdles of intermediate to advanced perl programming however the recipes in this book don't apply to your programming problems very often, and if they do you already know it because you did it hundred times before.
    The big problem I ahve with this book is that it really doesn't work well as a printed book. This needs to be in electronic form for easy search and copy'n'paste! I was lucky to get my hands on a electronic version before it went into print and bought the book later. It was nicer in zeroes and ones (allthough I didn't keep it as it didn't appear very legal).
    So I'd say for me it is a 7/10.
  • According to cgi-perl.com Matt Wright is co-authoring the Perl/CGI Cookbook. Despite the naming this book is not published by O'Reilly, but Wiley. I can't stop but wondering how you can become so famous writing poor code. I mean Wiley isn't excactly a student-press publisher and the site claims it would be the best-selling CGI book at Amazon.
    Matt Wright's CGI scripts are good examples how *NOT* to do it. I don't wanna know what horrible tales he is going to tell in the book.
    Who is going to save us from the wave of Wright-taught CGI-scripters wasting our resources?
    Anyone ever heard of the other author, Craig Patchett?
  • Posted by DonR:

    I personally learn by example. This book has been invaluable to many projects I have worked on. Its a must buy.
  • Posted by Anhydrous Cowboy:

    Yah, right, and the exception TESTS the rule, not PROVES the rule. What's your point, Poindexter?
  • Okay, flame me if you will...

    I'd like to learn Perl. I have a few applications for it. Unfortunately, I know very little about programming (I was pretty good with GW Basic and QuickBasic... but that was a *long* time ago). I was wondering, what would be the best way for me to back into programming and launch into Perl? Should I try the Camel book? I need a lot of hand holding...
  • hehe - Glad to see someone noticed :) I like to use billg's email address so that all flames are directed towards him instead of me...

    Anonynimity is your friend.
  • I'm only on chapter two of this book. While it is an extremely impressive and educational source of knowledge, I think it could have stood a little better editing. For example, Recipe 1.2 refers the reader to the use of the && operator in Recipe 8.13, which has no such operator (nor the and operator)!

    There have been at least two other errors, that I can't remember off the top of my head (nor find in the book on a quick scan, to be honest). All books have errors, but I'm only on chapter two, and minor details like this can be KILLERS in computer books. It's especially disappointing after the flawless presentation in Programming Perl.

    Nevertheless, I do recommend it. It saved me hours on the project I'm working on now!
  • I've done more than a couple of reviews for Slashdot myself, and there is one extremely simple reason why my reviews are overwhelmingly positive:

    I don't have time to read bad books.

    There are plenty of good books out there, and those are the ones I read. I review the books I read. Simple.

    In that respect, my reviews are less of "this book is good and I recommend it" and try to tackle more of "what this book is about and who it might apply to."

    I can't speak for Eugene.
  • I review for Slashdot as well.

    I've never ordered from Amazon.

    You don't have to either.
  • Well, as a professional software developer at a major Canadian software development corporation, I think that if I spend several hours writing up my thoughts on a relevant book I have read in its entirety, that qualifies as "editorial content."

    I have no problem giving a poor review to a poor book, even if I received it as a review copy. In truth, I purchase many books every month, have an enviable professional library as a result, and spend a significant portion of my personal time reading and absorbing them.

    In practice, I only tend to read useful and good books, so that weeds out poor reviews as a side effect. Anyone is free to disagree with my reviews, and to purchase or not purchase the book in question as they see fit.

    I don't purchase at Amazon, mostly because I'd just as soon order it at a local store. Price is not an issue for me personally, since I make a decent (though by no means complete!) salary.

    YMMV
  • I've read most of the Advanced Perl Programming book, but I didn't find that much useful info. I'd already done most of what was mentioned...

    btw, I've been programming Perl professionally for well over 3 years... guess it kinda makes a difference. I would say that most people would find APP quite useful.

    However, I will check out the perl cookbook. I'm particularly interested in the bit on daemons.

    The bit on efficiency and programming style near the end of the Camel Book is quite good too. The bit on how to style programming was interesting - it is almost identical to what I do! (I was already doing things that way before I read it...)

  • Well... I don't read books I don't like to the end, so it's hard to do a review of it. I expect the same applies to the other authors.
  • Programming Perl and Advanced Perl are excellent texts, if you know the commands and maybe not so much how to use them.

    The organizational structure of the Cookbook allows it to be not based on the language functions, but on what you want to do.

    I use this book more than my copy of Programming Perl, and feel it is essential for learning Perl. Mostly because the text Learning Perl doesn't support you in the high-end ideas you try to complete. This book was one of my favorite purchases and most used books. 11/10.
  • I can't recommend it enough.
    My parents gave it to me for my birthday (well I did hint pretty heavily).
    I've already worked through half the book and have actually used Perl in my job now.
    Definately get it.

    Kashani
  • If i remember correctly, the book includes an introduction by Larry Wall himself, stating that he has in fact learned a good amount from this book as well.
  • What's the point of reviewing a bad book? :)
    There's tons of them...
  • Amazon $31.96
    BarnesAndNoble $31.96
    Bookpool $24.95
    Shopping $19.97
    Spree $31.96

    Regards, Ralph.
  • Seen positively: It's a review of a good book that just happens to help finance Slashdot.

    Read the "Amazon Info" box by the review: "The books here are brought to us in Partnership with Amazon.com. If you follow the links around here, and eventually buy a book, we get a percentage of the cost!" The openness of the relationship is about the only thing that makes it acceptable to me.

    Seen negatively: The books reviewed are rather too often surprisingly expensive non-discounted books at Amazon, when they can be had *much* cheaper elsewhere. Here I start to smell a rat. Especially when the reviewer attempted to include pricing info from other sources but had the info edited out by Slashdot (as happened in this review).

    If the Slashdot affect works for book sales like it does for websites then CmdrTaco and Co. can be making a pile of cash off these reviews. If so, it can't be so healthy for a .org to operate like this. I think you're right to raise the possibility of the "advertising" polluting the editorial content.

    But who can you trust in this respect nowadays, anyhow?

    Regards, Ralph.
  • "A handy compendium of code snippets like the ones in this book will help solve the problem at hand, but won't help you design better programs."

    If the book was just snippets and descriptions, this would be true. But in most cases, a step-by-step description of how the code works is provided. This allows the reader to learn from the examples, not just blindly copy them.
  • I have all three. I would go with "Advanced Perl" and the cookbook. The Unix Resource Guide is pretty pricy. It is useful, but not as much as the other books. (And the most useful parts are just printed versions of the various perl docs.)

    Another recommended book is "mastering Regular Expressions" by Jeffrey E.F. Friedl. It explains regex for pretty much everything. (Not just Perl.) One of the most useful O'Reilly books out there.
  • I'd love to have a C version of this. I can pretty much do what I need in Perl, but now I'm eager to get more into C for CGI scripting, and K&R 2nd edition, for all its goodness, just doesn't _talk_ about how to do stuff like, say, open a filehandle piped to sendmail, or silly little crap like that. :)
  • A worthy addition to the two truly *essential* Perl books, namely:

    Programming Perl
    Advanced Perl Programming

    Accept no substitute ...

  • Perl for Dummies is a good starter book. It was a
    lot more help than Learning Perl, but I still
    refer to both.
    I just picked up the Perl Cookbook, and it looks
    like it will also be a huge benefit. I've
    reinvented the wheel (badly) several times for
    lack of good practical examples like these.

  • *Really* nasty reviews can be very entertaining, though. Things like the Bookwork column in the UK magazine Private Eye are fantastic. It's not just a case of bad notices - it's really brutal but very accurate (well written and argued) reviewing.

    I take the point about making money from sales, but perhaps if anyone is writing really acid reviews you could include them for sheer entertainment value.
  • Borders: $39.99 borders.com
    O'Reilly: $39.95 oreilly.com
    Amazon: $31.96 amazon.com
    BarnsAndNobel: $31.96 barnsandnobel.com
    BooksAMillion: $31.96 booksamillion.com
    Books: $31.91 books.com
    BuyBooks: $25.16 buybooks.com

    I was considering writing a free search engine
    that would find the cheapest book, CD, or Video
    by looking through the various sites. Do you think people would be interested in something like that?
  • How's about I...

    Call it FREE, make it FREE and we all get rich!
    ;-)
  • After talking about I wrote it and interfaced it to the web.

    I'd be interested in any feedback.

    Check it out at:
    http://expert.cc.purdue.edu/~bgann on/booksearch/ [purdue.edu]
  • Nope.. Learning Perl is probably the best tutorial book I've ever seen (language independent). And I'd highly reccommend it. Though, if you know your programming pretty well, I'd skip Learning Perl and go straight for Programming Perl 2nd Edition (the camel book).
  • IMHO, the Perl Resource Kit is a waste of money. It didn't give me anything much that I couldn't get for free from CPAN. If you don't have any internet connection at all, it might be worth-while, since it's pretty much just a shovelware distribution of CPAN.
  • 1.Two sections were transposed: "Anatomy of Chapter" should come before "A Code Feast". (author's negligence).

    2.Here's a list of prices (edited out):
    shopping.com: $19.95
    bookpool.com: $26.50
    amazon.com: $31.96

    Eugene Sotirescu
  • Problem is you can't really browse thru the kit, because it's usually shrink-wrapped.
    ORA's web site has some excerpts tho.
    The price is kinda steep, but check out bookpool's price ($90, $60 off the store price!) if you decide to go with it.
    If you haven't done OO in Perl, the Kit might help you use modules that need OO code (the pods are often stingy).
  • I agree with your approach. Allow me two points tho:
    1.You can't draw a meatcleaver distinction between decription and recommendation. "what this book is about and who it might apply to" often carries an implicit recommendation.
    2.The "Perl Cookbook" is a special case. I don't know many tech books that reach this quality of both code and delivery and can sustain it through over 400 pages. That's why this it gets an 'unmixed', "this book is good and I recommend it" review.
  • 1. The last sentence of the review says: ". . . this book is pretty much an essential companion to the Camel, as both resource and learning tool." 2. The sentence you quote means that you can't learn program structure by reading code excerpts, no matter how well commented they are. What to use as globals, how to build subroutines and modularize your program is a separate art. Eugene Sotirescu
  • Hmm... I don't like Matt Wright's perl code.
  • Shoot, you could do the same thing with a pro-Sun semi-tome such as the SysAdmin and Advanced SysAdmin guides.

    All software sucks, some just suck less than others.

The rule on staying alive as a program manager is to give 'em a number or give 'em a date, but never give 'em both at once.

Working...