Book Review: Advanced Perl Programming by Simon Cozens

Author: DrPatPublished: Jul 29, 2005 at 2:09 pm 4 comments

The second edition of Advanced Perl Programming, by Simon Cozens, is very different from the first edition, because it comes into a different world of Perl programming than the first, published in 1997, did. Cozens points out in the introduction the two reasons for this shift. The first was the development and introduction of Perl 6, which had the effect of stretching Perl 5, as thousands of Perl genies found ways to make the current version do things that were promised for Perl 6.

The second reason, though, was both more subtle and more powerful, a true paradigm shift. The focus of Perl programming had shifted "away from techniques and toward resources." Knowing where to find a tasty pearl of Perl and how to plug it into your own structure has become more important than knowing how to create it in the first place, because the resources are out there.

Camel button: Powered by Perl
     Camel = PerlBecause of the shift, Advanced Perl Programming concentrates on three crafty ways to use those resources. Cozens spells them out in Chapter 1, "Advanced Techniques":

I've said that there are no secret switches to turn on advanced features in Perl, and this means that everyone starts on a level playing field, in just the same way that Johan Sebastian Bach and a kid playing with a xylophone have precisely the same raw materials to work with... First, we'll look at introspection: programs looking at programs, figuring out how they work, and changing them... The second idea we'll look at is the class model... As this is an advanced book, we're going to learn how to subvert Perl's object-oriented model... Finally, there's the technique of what I call unexpected code—code that runs in places you might not expect it to... These three areas, together with the special case of Perl XS programming... delineate the fundamental techniques from which all advanced uses of Perl are made up.

Cozens has created a map for some fairly complex territory with these three classes of approach. The first chapter comprises a kind of legend for this map, detailing some "basic" applications of each class. For example, introspection is illustrated with glob aliasing, in which the pointer for a whole group of variables is "hijacked" (purposefully) to serve another glob. From there, he takes us swiftly through accessing glob elements ("to access the individual references, you can treat the glob itself as a very restricted hash..."), closures ("a code block that captures the environment where it's defined..."), AUTOLOAD, and "two of the most misunderstood pieces of Perl arcana," CORE and CORE::GLOBAL. By page 20, Cozens has pulled these six elements into service to show the power of introspection, and he's ready to introduce "messing with the model."

Exploration is always simpler when you have a map, but any explorer will tell you, a map is not sufficient in itself. To get the most from this book, you need to be fairly familiar with Perl, and it helps to have several other languages under your belt as well. Cozens occasionally intersperses Perl examples with code from Ruby and C, but the meat of his instruction comes in showing how even frequently-used Perl goodies have little-used "hooks" that allow them to be repurposed. So although "one of the draws of Ruby is that everything is an object," but "you can't do that in Perl, [because] 2 is not an object," by manipulating the model "we can fake it."

Continued on the next page Page 1 — Page 2

Article tags

Spread the word
Bookmark and Share
Profile image for DrPat

Article Author: DrPat

DrPat is the blog signature used by an old coot who hoards books, dances Argentine Tango, cooks a mean venison chili, and is happy to be along for the sag while my spouse does a marathon bicycle ride. …

Visit DrPat's author pageDrPat's Blog

Read comments on this article, and add some feedback of your own

Article comments

  • 1 - Aaman

    Jul 29, 2005 at 2:30 pm

    If I need introspection, I'll stick with one of the .NET languages like C# - they make it so easy

    Otherwise, Perl is very powerful for many tasks

  • 2 - DrPat

    Jul 29, 2005 at 2:36 pm

    Actually, "introspection" is used as a technique to create more-advanced Perl code. Qua introspection, it might make more sense to use another language, but that doesn't advance your use of Perl, does it?

  • 3 - bliffle

    Jun 23, 2007 at 9:23 am

    I did a bunch of perl programming around 2000 and thought it greatly inferior to Java. Also, the readability of other peoples code was horrible. But the parsing expressions were useful and concise, and I see that Ubuntu commandline uses them. Perl, like C and Python and Tcl and dozens of other languages, was designed to solve about 6 programming problems out of at least 1000, and thus is lame. in 50 years of programming I've only seen a couple that are comprehensive, like PL/I and Java.

  • 4 - Bill

    Oct 25, 2007 at 5:33 am

    bride-obscurity

Add your comment, speak your mind

Personal attacks are NOT allowed.
Please read our comment policy.

blogcritics lists for Jul 09, 2009

fresh articles Most recent articles site-wide

fresh comments Most recent comments site-wide

most comments Most comments in 24hrs

top writers Most prolific Blogcritics for June

top commenters Most prolific Commenters in 24 hrs