Perl Cookbook
by
Tom Christiansen and Nathan Torkington
Published by O'Reilly & Associates
Review by Nelson Bigelow, Jr.,
MELUG-Central
a division of
MELUG - MainE Linux Users Group
In his Forward to the Perl Cookbook, Larry Wall, the inventor of Perl, wrote, "The work
in question is so monumental that anything I could say here would be either redundant or
irrelevant." From here he proceeds to capitalize on the cooking analogy in his delightful
prose style, thus introducing this remarkable volume. And I find the meal to be delicious
and most agreeable.
For both authors Perl and recreational programming are among their hobbies. This
personal involvement has enabled them to create a work that is uniquely oriented the
practicing programmer and filled with practical solutions to a whole range of
programming problems. They have created a volume that is both a programmer's dream
and a treasure trove of Perl. There are hundreds of solutions, called "recipes", (334) and
over one hundred examples (126) of common problems. If you are a moderately
experienced Perl user, you can collect what you need and go right to work.
If you are a beginner or casual user, you will need more help to understand the recipes,
mainly because Perl is such an idiomatic language. The "Preface" lists a number of
references. I suggest Learning Perl, Learning Perl on Win32 Systems, and Programming
Perl.. The Perl CD Bookshelf is another valuable resource. All are published by
O'Reilly & Associates.
Every chapter begins with an "Introduction" giving important information on the
chapter's topic. For example, the chapter "Strings" is a "crash course" on Perl's handling
of text data. Another example is the chapter "Numbers" which discusses problems
associated with storage and processing of numbers and the background of their solution.
The recipes which follow all show you how to meet these challenges. Their style of
presentation reflects the authors' deep involvement with programming in general and
Perl in particular. Among them are Perl's handling of substrings, extracting characters
from a string, and many other techniques. There is even a recipe using Perl's Soundex
module, which allows you to distinguish between names that sound alike but are spelled
differently, such a Smith and Smythe. Another example is a method of comparing
floating-point numbers. These topics are often not adequately explained in programming
texts resulting in my spending many hours experimenting in order to understand them.
Most of the recipes consist of four sections, "Problem," "Solution," "Discussion," and
"See Also." The Discussion section furnishes detailed information on the Solution and
the See Also section refers you to related topics. A few recipes depart from this format
in that they contain complete commented programs and an explanation of their operation.
The first five chapters illustrate the use of Perl's basic data types. These are followed by
a chapter on pattern matching, a core issue of Perl. Most computer languages do not
have such a facility. After all, the name "Perl" is an acronym based on "Practical
Extraction and Report Language." I read through the solutions (recipes) and found that,
though they are well explained, I will need further study in order to apply them.
But Perl is more than just a text-handling, pattern-matching language. Originally, it was
designed to be a systems programming language. And so the next three chapters cover
everything you need to work with disk files and directories. Following are chapters on
all the constructs that are found in a modern computer language, subroutines, references,
records, packages, libraries, modules, and object-oriented mechanisms.
Next, the chapter "Database Access" gives you recipes for creating and manipulating
data files. Perl can work with many different formats, such as Btrieve, DB2, MySQL,
Oracle, and Xbase, to mention a few. More than 50 modules that make this possible are
available from CPAN (Comprehensive Perl Archive Network) on the Internet. As
examples, the last two recipes show you how to execute SQL commands and how to
extract Netscape's history.db file.
Then comes a chapter on a subject that many computer language manuals don't even
bother with at all, the user interface. Here, once again, the orientation of the book
towards programmers shines forth. Two topics covered which are notably absent from
manuals for other languages are the handling of command line parameters and changing
text color. Recipes for both full-screen mode and GUI (graphical user interface) mode
are given. For example, there is a program to "clear the screen, move the cursor, and
write anywhere on the screen." Examples for the GUI include creating menus and
creating dialog boxes. Both modes are implemented through the use of Perl toolkits.
Systems programming is covered in the next chapter, and the book concludes with
chapters on sockets, internet services, CGI programming and web automation.
In conclusion, I heartily recommend this book for the practical solutions it provides and
the educational value of its explanations and examples. I particularly appreciate its
orientation toward the needs of the programmer. If you are involved with Perl, whether
as a beginner or as an experienced user, you need this book.
For further information on this book and to obtain a sample chapter and all the code, visit
the site http://www.oreilly.com/. The book sells for $39.95 and contains 757-pages,
including the index. It is published by O'Reilly and Associates, Sebastopol, California.