A Review of O’Reilly’s Perl Cookbook

[SomeDudeSays.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.]

O’Reilly’s Perl Cookbook is one of the first books I got for learning Perl, along with “The Camel Book” (Programming in Perl). The Perl Cookbook is the next step after starting to learn and work with the language. It’s useful from very early on, and I have referenced it for ideas of how to approach a problem even when working with Perl professionally.

Despite the fact I don’t code in Perl anymore, Perl was my first language I could say I mastered. I used to work professionally with Perl making microservices on a custom virtualization framework before they had a name, and built countless tools in it ranging from data munging to a full ERP with its own scripting language. Unfortunately, I can’t make it a justifiable option where I work, but Perl will always remain the baseline I compare every language to even if I can’t use it regularly.

I’ve long since parted with every Perl book except for the Perl Cookbook, and Algorithms with Perl. I wanted to keep my copy of Modern Perl, but it walked off. These three books will take you the furthest once you get past the bare basics. Others may serve as a great reference, but if your shelf space is limited, get them digitally.

What’s in the Perl Cookbook?

The Perl Cookbook is like most programming cookbooks for the general organization. It is composed of a series of recipes on how to approach various problems. The book is further divided into classes of problems, like those involving strings, or those involving regex.

Each chapter has an introduction explaining the class of problem for the chapter and what Perl does to solve it. For strings, Perl is extraordinarily powerful, but isn’t probably going to be anyone’s first choice for a graphical program. Each subsection of the chapter is a specific problem and how to solve it, as well as a reference for further reading.

The vast majority of the topics cover the core language. Other parts cover libraries which are useful in more professional projects. The book is a bit older so it doesn’t really delve into any newer frameworks. Everything in this book is going to be usable on even the oldest (externally accessible) boxes running Perl.

Topics Covered

The book starts with Perl’s strengths, text processing via strings, and moves on into other basics of the language. It covers numbers, dates and times, arrays, hashes, regex and patterns, files, directories, subroutines, references, packages, and objects. The Perl Cookbook then moves on to database access (SQL and similar via DBI), user interfaces, process management, TCP/IP network sockets, internet services, CGI programming, and web automation.

This is a cookbook style programming book, so it won’t go too into depth what each topic is or why it matters (to borrow a cooking reference, it won’t tell you what a roux does), but it does show you how to put the pieces together to get a solution. You don’t buy a cookbook expecting to learn how to saute onions, so don’t buy this book alone expecting to learn Perl in its entirety. This book will give you the tools and tricks to improve your Perl, but you need to know the basics to make it work for you.

What Makes It Great

Most cookbook programming resources suffer from either being too specific for new learners, or too simple for advanced learners. The Perl Cookbook manages to stay fresh for all levels, though some sections are obviously more advanced than others. There isn’t a group of Perl programmers who won’t get something from this book (unless you’re at the level you’re taking apart the source of the Perl VM and interpreter or looking to do something extremely specific).

The book covers almost any scenario a new programmer would run into, and basically the Pareto Principle worth for intermediate programmers. For advanced programmers, it breaks down a little, but many of the common items you don’t commit to memory, but don’t want to reinvent each time are in this book. It also makes a great refresher if you swap languages for a while.

I have used this book many times to refresh myself on idioms and ways of approaching problems in Perl after working in similar (enough) languages for a while (like Ruby or Lua). The solutions are all extremely relevant to the specific problems. Even if the problem’s solution doesn’t work for you, it will at least help put you on the right track.

What To Watch For

There isn’t really anything “wrong” in the book, but some of the solutions show their age. CGI is dead. Telnet is not best practice. It’s littered with artifacts of the past (which is ultimately the same reason Perl has died in the mainstream in my opinion, but we won’t get into that here).

You need to be able to sort out what is relevant and what isn’t. It gives you the best practice, or at least good enough for a few pages worth best practice for most of the problems, but you need to know what problems are worth answering.

Let CGI die, it’s the wrong way to handle the modern internet. Stay away from some of the networking solutions unless you know when they are worth using. None of it is wrong, but it’s still a good answer to a bad question at best for some of the sections.

This isn’t a con per se, but a warning to those looking at buying this book who don’t use a POSIX OS (Linux, MacOS, BSD, etc.). A lot of the command based solutions just won’t work on Windows. I’m not really a fan of OS libraries (Lua article, but relevant philosophy), but I accept they’re a necessary evil. You can use the Linux Subsystem for Windows or similar to make this work on Windows, but you’re still going to hit a fundamental disconnect when you dig deep enough at an OS level.

Digital or Physical?

If you’re new to Perl or actively coding, get the physical copy. It’s a lot easier to thumb through a physical book and stumble on something useful (and to be honest, you can probably get it cheaper than the digital version). Also, I find it substantially easier to search through a physical book, so if this isn’t the case for you, take it with a grain of salt.

Personally, I have not bought the ebook version of this book, but coding books tend to be formatted poorly on most devices. Your mileage may vary here, but ultimately, the convenience of a physical book still beats a digital copy for me for almost everything. The one exception is if you plan to use this as a refresher (it won’t matter as much then), or just don’t have the physical space for a copy.

Conclusion

This is an amazing resource for almost every Perl programmer. Beginners will learn a lot from it, intermediate level programmers will have a great tool for common problems, and advanced programmers get a reference for many real life, common problems. It won’t teach you the language, but it will teach you how to use it and make it work for you.

The Perl Cookbook is an indispensable resource for anyone learning or using Perl. It has a few warts, but overall, it is the best bang for your buck for a non-introductory Perl resource. There isn’t another book, cookbook or otherwise, which comes close to the applicability of the Perl Cookbook.

Get a copy here.

Categories: Reviews
Some Dude: