Programming perl by Larry Wall and Randal L. Schwartz
443 pages (plus index), 1991, O'Reilly and Associates, Inc.
Review score: ** out of *****

The perl programming language was originally implemented (around 1990) on UNIX and has since spread to other operating systems, including Windows NT and Windows 95. Perl was designed for writing scripts for applications like text processing and system administration. In contrast to C and C++, which are almost always compiled into native machine code, perl is compiled into a pseudo-code for a softare machine (an interpreter). Immediately after a perl script is successfully compiled, it is executed. This gives perl an interactive feel, which has contributed to its popularity.

Larry Wall, the designer of the perl langauge and the original implementer of the perl compiler and interpreter is a prolific programmer and a generous person. He has placed the source for perl in the public domain (under the GNU license). The perl software is not the first widely used application developed by Larry Wall. He is also the author of rn, which at one time was a widely used net news reader (back in "the good old days", when news was moved around by a program called uucp and there were no children on the Internet, nor pinheads in congress trying to protect them from naughty ideas and pitures).

Since I admire Larry Wall, I would really like to say that I liked his book. Unfortunately I found it poorly organized and difficult to use. I had these problems despite the fact that I am a long time UNIX user and I have written both csh and awk scripts. I am also fluent in both C and C++.

The perl programming language is a complete programming language that can be used to support a wide variety of algorithms. Although it would be unwise to use perl for writing complex numeric code, it could be done. For example, the perl subroutine below implements square root using Newton's approximation.

# Square root, via Newton's approximation
sub sqrt {
  local($f) = @_;
  local($res, $last_s);
  local($eps) = 0.00005;

  $res = $f;
  $last_s = 0.0;
  $error = $f;  
  while ( $error > $eps ) {
    $last_s = $res;
    $res = ($res + $f/$res) / 2.0;
    $error = $last_s - $res;
  return( $res );
} # sqrt

The size of the perl language and its quirky syntax and semantics make it a serious challenge to document. The first three chapters in Programming perl are

  1. An Overview of Perl
  2. Practical Programming
  3. The Gory Details

The first two chapters introduce perl and show how it can be used to write some simple scripts. The third chapter attempts to provide a detailed look at the syntax and semantics of perl. This is a popular way to structure a book on a programming language. For example, this organization has been used successfully in The C Programming Language by Kernighan and Ritchie. But Wall and Schwartz do not take a methodical approach to introducing the perl language. They first introduce the =~ operator in a table that include twenty other operators. There is no further comment on this commonly used operator. It took me a while to catch on to the fact that the =~ operator applies the string pattern matching or transformation rule on the right hand side to the variable on the left. So, for example,

$word =~ tr/a-z/A-Z/;

will capitolize the contents of $word.

I have also not found a place where Wall and Schwartz fully define the operation of associative arrays. These are introduced early on in the book, but I never did find a place that defined the value of an associative array expression when the element is not in the array. I wanted this value to be null, but apparently this is not the case.

When covering the result returned by subroutines, they mention that a subroutine returns the value of its last expression. It is only much later in the book that there is a brief mention that perl supports a return statement. Unfortunately no example is given and I was left guessing that it must follow C syntax (which turned out to be correct).

Especially for the reader who is already experienced with C and UNIX, a book on perl will be skimmed to pick up the language. What I hoped for was a methodical description of each language feature. Since this is not quite there, care must be taken in reading the book, so that some point, briefly mentioned, is not missed. And even then, the book can be frustrating, since it does not contain the many small examples needed to demonstrate each language feature.

Although Programming perl could be improved, it appears to be the standard reference on perl in the same way that Kernighan and Ritchie's book was the standard reference (along with the PCC compiler) for C for many years. This makes Programming perl an essencial reference for the serious perl programmer. The book documents version 4 of Perl. Version 5 is now available and it supports a number of features not documented in Programming perl.

Ian Kaplan - 8/96

This review is of the first edition. Apparently there is a new second edition available as of October, 1996.

When ever the C compiler flags a typo in a variable name with an undeclared variable error, I am reminded of how glad I am that I don't use Perl for large projects. So I'm not planning on running out and buying the new edition of this book. The first edition seems to be sufficient for the occasional perl script I write. However, if the O'Reilly Press would like to send me a review copy, I will be happy to write a review of the second edition.

Ian Kaplan - 10/96

Book review table of contents

Adventures with Perl

software source page

back to home page