Wednesday, July 20, 2005

Three Approaches: Advanced Perl Programming by Simon Cozens

PANTHER

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 = Perl

Because 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."

Once we are somewhat familiar with his three techniques, Cozens leads us further into dark territory. We look at advanced parsing techniques, for dealing with data that isn't presented in a regular, structured format. He covers both top-down and bottom-up parsing, using Perl tools that are already available from CPAN and other sources. Next, he takes us through templating tools (one of those "perfectly good wheels that every journeyman Perl programmer reinvents"), beginning with "format" and Text::Autoformat, then diving into HTML::Template (a Perl program that outputs HTML code) and HTML::Mason (HTML code that incorporates and runs snippets of Perl).

In Chapter 4, "Objects, Databases and Applications," the author addresses one of Perl's great strengths. Every advanced Perl user can appreciate the value of neat techniques for sorting and manipulating data. What Cozens has done, though, is to move beyond the ordinary here, showing us how to put existing tools and applications together in vital new ways. This is a chapter full of little "trap" icons, too—the icons indicate pitfalls of Perl programs, with valuable guidance that will help you avoid the trap.

The next chapter covers Perl's abilities to process natural languages, so the computer can "understand" them. The author uses a real-world issue—identifying spam—to illustrate how Perl can do this. Then he covers Perl and Unicode, and the Perl Object Environment, and a section on testing that advanced code you've written.

The final chapters detail how inline extensions let Perl programs run snippets of other executable code, and how you can play with with the stuff you've learned. In using inline extensions, it helps to have that other programming language under your belt—Cozens uses C, Python, Ruby and CPR. The toy-filled final chapter has poetry playthings and even golf. My favorite, though, is "bleach," a module that does nothing much—but so cleverly, it's fun to trace its activity through the code!

Advanced Perl Programming is Safari-enabled, which means its contents are searchable online, if you have a subscription. But if you're an intermediate Perl user, wanting to move up a notch, what you really want is a copy of this manual at your desk, and hours to spend working through the examples. It's definitely worth the time.
0596004567,0596101058,0596100922,0596001738,0596000278,1565926994,1565924193


Please join us at BlogCritics to comment on this review.

4 Comments:

Anonymous Anonymous said...

thats a very good review. I found some free perl books online which might be useful to your readers.

http://vaandoo.blogspot.com/2006/08/top-4-perl-books-for-free-download.html

8/29/2006 11:45 PM  
Anonymous Anonymous said...

oops. sorry guys. looks like the URL is not enabled. Here you go:
Top 4 Perl Books for free download.

8/29/2006 11:47 PM  
Anonymous Anonymous said...

No deposit bez depozytu senza depozito free non depositare poker bonus free
do odbioru bonusu trzeba się spieszyć bo znikna z powierzchi ziemi
aktualne bonusy poker online free
poker texas lub także internetowy muszę napisać więcej unikalnego tekstu tutaj , bo mi się nudzi graj bez depozytu
online poker za free - sponsor
platforma promocyjna będzie dziś w bonusie bez deponowanym graj w omaha hold'em lub titan poker
bez depozytu bonus free full tilt wtop czyli world tour of poker aktualne zastawienie bonusów
-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-POKER-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-
bankroll $50 - INTERNATIONAL players
To be eligible to withdraw this bonuses or bankroll and Your winning You will have to play a minimum amount of raked hands at the poker room.
free poker money - online poker page free start up money
poker sign up actual free money
Complete list of the best actual free poker cash poker bankroll without requirments online site & pages free start up money for us.
Please note that this tool is not a 90% accurate but $50 representation of search engine algorithms of wsop poker and should not be used
free bankroll no deposit required
free bankroll no deposit cash required and best sponsor
Play poker online for free :)

6/07/2009 7:25 AM  
Blogger samraat said...

sangambayard-c-m.com

4/03/2010 10:46 PM  

Post a Comment

<< Home