 | Level: Introductory Teodor Zlatanov (tzz@bu.edu), Programmer, Gold Software Systems
01 Sep 2000 The release of the third edition of Programming Perl is a significant development for the Perl community. After four years, this excellent book has been updated with information about the new 5.6.0 release, and the new sections almost double the page count of the second edition. In addition to reviewing the book, Teodor Zlatanov examines how well the book reflects the changes made until the 5.6.0 release of Perl.
The third edition of Programming Perl is impressive from the start. It
has almost double the page count of the second edition. The cover is the
same, except for the discreet banner in the top right corner, the TMTOWTDI
("There's More Than One Way To Do It") slogan at the top, and the list of
authors. The similarity is only skin deep, however, as a look at the table
of contents will quickly dispel any illusions that this book is only a
revision. The third edition covers a multitude of changes made in the Perl
language since version 5.003. It has extended or created many sections,
while preserving cohesiveness and consistency. The authors
Larry Wall and Tom Christiansen are back in this edition, while Randal L.
Schwartz has been replaced by Jon Orwant. Larry Wall is the creator of the
Perl language. Tom Christiansen is known as the caretaker of the Perl
online documentation, and is the principal author of The Perl Cookbook (an
indispensable resource for the Perl programmer). Jon Orwant is the Chief
Technology Officer of O'Reilly & Associates and editor-in-chief of The Perl
Journal, the best-known and perhaps most highly regarded Perl magazine. The style of
the previous editions has been preserved. Lucid exposition interspersed with
good examples and many jokes that will strike a chord with programmers are
prevalent in the text. The editor, Linda Mui, and the technical editor, Nathan Torkington, have
done an excellent job as well. There were very few errors in the book,
which is impressive considering the page count. The O'Reilly Web site
(see Resources) has a link to the updated errata. This review will have two key elements. It is a review of the book,
but also a review (though in a much more cursory fashion) of the changes in Perl
since version 5.003. The third edition of Programming Perl incorporates
those changes, but does not distinguish between features from 5.004, 5.005,
and 5.6.0. This is unfortunate, because there are major differences between
the two versions, and many Perl sites running 5.005, for example, need to
know what has changed with 5.6.0, compared with the changes from 5.003 to
5.005. The "perldoc perldelta" command will show the changes made since the last
version, so in a 5.6.0 installation you can see what has changed since
5.005. Similarly, "perldoc perl5004delta" will show what changes were made
for 5.004. The information is also available on the Web at
Perl.com (see Resources), but it is sufficiently technical that a more gentle
summary should have been in the book.
What's new
There are many things new with Perl since the 5.003 release. New language
constructs, modules, pragmas, and capabilities abound. The following is a summary of
changes on the user side, using the relevant perldoc pages. You should
consult them yourself, since this summary omits many minor but possibly
significant changes. | 5.003 to 5.004 | 5.004 to 5.005 | 5.005 to 5.6.0 |
- Better syntax for subroutine references ($ref->{parameters))
- delete works on hash slices
- printf and sprintf are internally implemented
- Preallocating hash size (keys %hash = 2000)
- my can be used in a control structure (foreach my $i (1..5) {})
- use VERSION requires that version of Perl (also possible for modules)
- New OO methods and capabilities (isa, can)
- Module autoloading, testing against uninstalled versions
- Constants (use constant A => 5)
- CGI module
- CPAN module
- UNIVERSAL module
- Math::Complex, Math::Trig modules, reaffirming Perl's commitment to mathematicians worldwide
- pod2html
- Many new perldocs
|
- Improved regular expressions (lookahead, code execution, conditional parts)
- Pseudohashes (as useful as hashes, as fast as arrays)
- EXPR foreach EXPR support
- Better precompiled regular expressions
- Better substr (can replace matches too)
- Better splice (negative argument works backwards)
- One-line loops and logical statements
- Data::Dumper (an indispensable debugging tool)
- File::Spec (portable file operations)
- Test (for writing test suites)
- Many new perldocs
|
- Unicode and UTF-8 support
- Interpolated named characters and binary numbers
- Version strings (v-strings, e.g. 'v5.6.0')
- New subroutine attributes syntax
- Large file support (more than 2GB in size, if supported)
- POSIX character classes
- exists() and delete() can be used on array elements
- Even better pseudo-hashes (using the fields pragma)
- Better Benchmark module
- Java Perl Lingo included
- Term::ANSIColor (colored output where supported)
- Many new perldocs
|
 |
Overview and some gory details
The overview sections have changed little from the second edition, but they
still provide an adequate introduction to the Perl language, mixed with "the
appropriate amount of fun." A more detailed overview of the language is given in Chapters 2 through 4.
The content is updated in all the right places, including the invaluable "use
constant" pragma. Again, there is little different so far from the second
edition.
Pattern matching
The chapter on pattern matching is new. The second edition had no more than
35 pages dedicated to this complicated topic, while the third edition has
nearly 80. There are examples for all the features, and all the advanced
and new ones are explained in depth. Where to start? Lookahead, cloistered
modifiers, conditional sections, named characters, they're all there. The
named characters and character classes are Unicode-enabled, and examples are
shown for them. POSIX character classes are also listed. The pattern matching chapter is sufficient for learning about this
fascinating side of Perl. It carries a wise warning ("Don't try to do
everything with regular expressions"), and that is something every Perl
novice should avoid. It is impossible to capture in a chapter all the
applications of regular expressions, however, and for those interested in
further information Mastering Regular Expressions (see Resources) by Jeffrey E. F. Friedl
is a good bet.
Subroutines, references, and data structures
The subroutines chapter covers new syntax (prototypes and attributes), plus
the brand new lvalue attribute (as of 5.6.0). Imagine being able to modify
the return value of your subroutine! Until now, special care had to be
taken to allow modification of object attributes, for example. With lvalue
subroutines, you can directly affect scalars returned by subroutines.
Prototypes are another important feature, and should be used whenever
possible (but not to "retrofit prototypes onto [old functions]"). This is a
short but important chapter. The chapter on references is important for those who need to learn about
data structures and passing values with Perl. Anonymous data (arrays,
hashes, and subroutines), closures, pseudohashes, hash slices, and weak
references are covered in detail. The examples are good, as usual. The
coverage of pseudohashes is particularly useful for anyone writing classes
with named fields that need speed. The data structures chapter is complete and useful, though Mastering
Algorithms with Perl (see Resources) by Jon Orwant, Jarkko Hietaniemi, and John Macdonald
is necessary for anyone trying to implement complicated data structures with
Perl. The chapter in Programming Perl is, nevertheless, a good
introduction with many examples. It also mentions the indispensable
Data::Dumper module, used here for saving and restoring data.
Formats
The formats chapter covers a feature of Perl that is not widely used today.
It is a combination of FORTRAN's output formatting keywords, BASIC's output
layout, and nroff's ideology. If you have used any of those three, you may
find formats convenient and useful. There is nothing noticeably new in this
chapter, except that it's a chapter now where it used to be a section. At 6
pages, it's hard to see a reason for making it a chapter.
Packages, modules, objects, overloading, and tied variables
In the second edition of Programming Perl, object-oriented programming was
not emphasized. The section on objects was small and offered little help
with intensive OO methodology in Perl. This has changed with the third
edition. The chapter on objects is a longer, more detailed exposition of OO
in Perl, though it is still somewhat neglected in the book as a whole.
Features like the UNIVERSAL class's isa() and can() methods, Class::Struct,
and lvalue class methods are gently explained. Packages and modules are important to any Perl programmer. The new chapters
on those features are slightly longer than in the second edition, but
probably should have been merged into one chapter as they are only a few
pages each. They are important reading to anyone concerned with reuse of
their Perl code (and this should be everyone), but there's little new since
the second edition, other than new examples and updates for new features.
Required module versions, for example, are covered (use MODULE VERSION). The chapter on operator overloading is lengthy and useful. Moreover, it is
completely new, because in the second edition there was no way to overload
operators in Perl. This is a significant language shift, and the chapter
documents it well. There are many examples covering the range from simple
(addition/subtraction overloading) to the complex (overloading numeric
constants and run-time overloading). The chapter on tied variables covers the essentials of this useful technique,
and is updated with methods for tying a filehandle, and a list of Tie
modules on CPAN. There are also more examples and detail for the standard
scalar, array, and hash tying methods.
Unicode
It is difficult to support Unicode, and the chapter on that topic explains
why. The UTF-8 encoding is the one that Perl implements best. There are
others (UTF-16 and UTF-32, for example) defined by the Unicode consortium,
but UTF-8 is the best supported encoding for international character sets.
The Unicode resources at the end of this chapter, particularly the Perl,
Unicode, and I18N FAQ will provide a more complete picture of what made it
into the 5.6.0 release of Perl, and what didn't. The book does not
distinguish well between Unicode as a character mapping and the UTF-8
encoding. A neat example shows a Perl program written in UTF-8 encoding, so the
variable names can use non-ASCII letters. Bringing more people into the
Perl community should be easier when Perl is flexible enough to speak their
language. Unicode support in Perl as of 5.6.0 is a step in the right direction. It is
not complete, however, and caution should be used. There are CPAN Unicode
modules that work correctly with older versions of Perl as well as 5.6.0,
and they should be used if appropriate. As an aside, getting simple
applications like xterm and mutt on Linux to support UTF-8 encodings can be
quite challenging as well. UTF-8 is a fairly new standard, and support for
it is just starting to percolate into software. Perl loses out to Java in
Unicode support for now, which is not surprising since Java was designed to
support Unicode from its inception.
IPC and threads
The chapter on IPC (inter-process communications) is an expanded version of
the IPC section in the second edition. New and better examples are
provided, and it is remarkable how a module like IO::Socket::INET can
simplify the chore of writing a network server. Also, a neat example of the
use of the new v-strings to send CR/LF is shown. Threads are finally a stable (sort of) feature in Perl 5.6.0, and the
chapter on them is a good resource for the beginning threads programmer.
There is a brief description of threading as an algorithmic approach, a
justification for the UNIX fork-based threading model we all love and hate,
and some pretty good examples, including the use of the lock function and
subroutine attribute. Unfortunately, you still have to build your Perl to
support threads explicitly, because the threaded Perl interpreter is "pretty
much guaranteed" to run slower than the plain non-threaded one.
CLI and debugging
The CLI (command-line interface) chapter is a must-read. All the
information in it is guaranteed to save you time at some point in the
future, whether through clever use of the -p switch, or through the PERL5LIB
variable. Learn it thoroughly. This chapter is updated from the related
section in the second edition, most notably by including more information
about the environment variables that affect the Perl interpreter, and which
were not mentioned at all in the second edition. The saddest thing about the chapter on debugging is what neglects to mention. Despite all of its power and elegance, the built-in Perl debugger
does not come close to the ptkdb debugger available from CPAN. Check ptkdb
out on CPAN, and you will probably agree that it is a very good tool, at the
very least. ptkdb may have been omitted because it does not run on every
platform (it requires the Tk module, for one), but for a tool this powerful
and useful, a simple mention would have been more than welcome. If you like
the built-in debugger, or you have to use it because ptkdb does not run on
your platform, the chapter will be undoubtedly useful. There's 10 more
pages from the second edition, full of technical information and examples.
Interoperability with Emacs is mentioned as well, though without specifics
on setup and use. The Profiler section is last, pending any NBC lawsuits.
Who knew Larry Wall watched so much TV?
Compiling and internals
The chapter on compiling is all about the internals of Perl. It is a
fascinating read for the technically minded, and is helpful in understanding
how the BEGIN/END/CHECK/INIT subroutines work, and how modules are used. The internals chapter should probably have been merged with the compiling
chapter. It is an excellent introduction to arcane (for most Perl users)
subjects like embedding Perl in your programs or extending Perl with C code.
It is too brief, unfortunately, but perhaps that is consistent with the
overall beginner-to-intermediate level of the book.
Perl culture
The most pleasant surprise in the third edition are the "Perl as Culture"
chapters. They are an excellent introduction to all the things that make
Perl more than a language, a community. These chapters are greatly expanded
versions of a few sections in the second edition, and a fascinating read. The CPAN chapter is the starting point for anyone seriously interested in
Perl development. CPAN is the best resource for Perl modules, and a chapter
devoted to it is greatly appreciated. The security chapter is also expanded significantly from the second edition.
This is practical advice, and contains many useful examples. The original 4
pages have become 25 or so, and there isn't a single line you should miss.
There is information specific to security with CGI programs (including, but
not restricted to, the CGI module). The chapters on common practices, writing portable Perl, POD (Plain Old
Documentation), and Perl culture are well written and updated, and the examples
are very good. These chapters should be read by anyone interested in
participating in the Perl community, actively or passively. There's a lot
to be learned from gems like "Black Perl."
Special names, functions, pragmas, and standard modules
The special names, functions, pragmas, and standard modules chapters are
complete and well illustrated. Updates on new features are especially
welcome, and the examples do a good job of bringing Perl 5.6.0 to life. It
is nice that the technical reference section is really at the end of the
book, where in the second edition it lay before the chapter on other
oddments (called "Perl as Culture" and split into several chapters in the
third edition). A small discussion of Unicode compliance of modules and functions would have
been useful for those interested in per-function and per-module compliance,
but the hope expressed in the Unicode chapter is that everything in Perl can
be magically made Unicode-compliant with the "use utf8" pragma.
Conclusion
All in all, the third edition of this very popular book is a major event in Perl's
history. The release of version 5.6.0 brought many software improvements to
the Perl community, but it also made the second edition significantly
outdated. This gap is remedied by the third edition. Still, this book is
no mere upgrade. Several sections are completely new, and others are more
than twice their original size in the second edition. New modules, pragmas,
functions, and capabilities are shown in action with great examples. Perl
programmers should consider purchasing the third edition of Programming
Perl for all these reasons, but most of all because this is now the
definite and best reference for the Perl language.
Resources - Read Ted's other Perl articles in the "Cultured Perl" series on developerWorks.
-
CPAN has all the Perl modules you ever wanted.
-
Perl.com offers Perl information and related resources.
-
Programming Perl Third Edition
by Larry Wall, Tom Christiansen, and
Jon Orwant (O'Reilly & Associates, 2000) is the best guide to Perl
today, up-to-date with 5.005 and 5.6.0 now.
-
Mastering Regular Expressions
by Jeffrey E. F. Friedl (O'Reilly & Associates, 1997) is a standard and definitive reference on regular expressions.
-
O'Reilly & Associates are the publishers of Programming Perl and many other books mentioned in this article.
- Unicode resources:
About the author  | 
|  | Teodor Zlatanov graduated with an M.S. in computer engineering from Boston
University in 1999. He has worked as a programmer since 1992, using Perl,
Java, C, and C++. His interests are in open source work on text parsing,
3-tier client-server database architectures, UNIX system administration,
CORBA, and project management. He can be contacted at
tzz@bu.edu. |
Rate this page
|  |