The following book reviews are the copyright of their respective authors and no part should be reproduced without the express permission of the author. Publishers and Authors of the books reviewed may reproduce the whole or extracts of a review for their book. To request copyright permission please email firstname.lastname@example.org.
All the reviews herein are the opinions of the reviewer and are not necessarily the views of Birmingham Perl Mongers and its members. If you feel a review or comment has been made in error, please contact email@example.com to rectify the situation.
Static Link: http://birmingham.pm.org/reviews/5
|Title:||Learning Perl Objects, References & Modules|
|Author(s):||Randal L. Schwartz (with Tom Phoenix)|
<blockquote>Following the successful format of Learning Perl, each chapter in the book is designed to be small enough to be read in just an hour or two, ending with a series of exercises to help you practice what you've learnt. To use the book, you just need to be familiar with the material in Learning Perl and have the ambition to go further.</blockquote>
That's probably the most complete summary of the book that you can get, taken from the back cover. Since writing Learning Perl, Randal Schwartz has had first hand experience of seeing how students understand the concepts and idioms of Perl programming. The world has also changed since Learning Perl was written, when much of the readership was based in Perl4. Now we're approaching the dawn of Perl6. In the intervening years Perl5 has grown and matured, and much of what is missing between Learning Perl and Programming Perl, along with a few side roads, is included here. In fact I'm surprised the book hasn't been written before now.
The book, as the summary says, is split into logical parts, each with a set of example exercises to help affirm what was discussed in the chapter. I personally like books like this, as it helps to clarify what you know and learn as you go along. The exercises are not rocket science and are well focused on the chapter.
Following the Introduction, we start with Building Larger Programs. The common practice of cut-n-paste has been done by every single programmer I've ever met. It's how we start. However, it can quickly become a headache. This chapter looks at the different ways you can include reusable chunks of code in your program. Perl philosophy of TMTOWTDI is true here, and the chapter guides us through the <code>eval</code>/<code>do</code>/<code>require</code> methods, introduces <code>@INC</code> and finally explains the more stable usage of packages and namespaces. For such a powerful concept to get across, it's good to see it was important enough to put in as the first programming chapter.
Next up are two chapters covering Referencing and Scoping. I have known experienced programmers to misunderstand both and these two chapters pretty much cover all bases quite nicely. My only suggestion would have been to include Mark Jason Dominus' model from his Glob explanation in Tricks Of The Wizard to explain references, via the use of stash diagrams.
An important aspect of programming is hidden away on p24. "... various levels of optimisation can lead to obfuscation. Be sure to consider where your head will be a month from now when you have to reread your own code. If that's not enough, consider the new person who takes over your job after you have left."
Most find C pointers scary, references in Perl can be just as confusing. Clarity and an explanation of why you are doing what you are doing are always useful. But try not to go overboard (Gilligan's Island examples not withstanding). In discussing scope, reference counting is also covered, along with some basic examples. Without saying so, it is the basis for understanding closures. Also covered here are anonymous arrays & hashes and autovivification. Like much of the early chapters, the gems of knowledge such as these are the building blocks for bigger and more powerful concepts.
The next chapter looks at Manipulating Complex Data Structures. Using the Perl debugger, Randal shows us how a simple nested hash is created. Then using <code>Data::Dumper</code> and <code>Storable</code> he shows how we can extend this ability within our program. The tools <code>map</code> and <code>grep</code> help out here too. <code>Storable</code> is a very useful module, now part of the core, and is worth looking into if you don't use it already.
On to Subroutine References or coderefs. Of themselves these can be quite useful, but as callbacks and closures they become much more powerful. Using <code>File::Find</code> we can see how both are used. In Practical Referencing Tricks, we are guided through some very useful Perl idioms. Sorting and recursion are commonly used, and here we are shown some better methods of using them. Even the Schwartzian Transform gets a look-in. Personally I thought the Guttman-Rosler technique also deserved a mention.
Halfway through the book (pages wise) and we're on to Objects. The next four chapters are concerned with creating objected oriented APIs for modules. Everything in the preceding chapters were the building blocks for bigger concepts, and objects are a very handy bigger concept to know. It should be noted that much of the content of this chapter is taken from perlboot, which Randal wrote, with a few additions. The chapters build up the API from first principles. Personally I found this a bit too over the top, as anyone reading the book, who has read at least one other Perl book, will already grasp many of the basics. Much of the explanation along the way to the final API is knocked down and discarded anyway. Along the way we get <code>@ISA</code>, <code>SUPER</code>, <code>DESTROY</code>, <code>UNIVERSAL</code>, and <code>AUTOLOAD</code> explained very clearly. There is much more to object orientated programming than is covered here, but there is certainly enough to simplify some of the complexities.
Once you've created a Perl module, which you will have if you're completing the exercises after each chapter, you will typically have two ways to access the functionality within. Either via an object oriented API or a function oriented API. The next chapter looks at both of these, together with how to use <code>Exporter</code>, <code>use</code> & <code>require</code>, <code>use lib</code> and the <code>import</code> (and <code>unimport</code>) function.
Next up is Writing A Distribution, which was perhaps the most interesting chapter for me. If you've reached this far and have tried to put together your own distribution, you'll know the information online is a bit sporadic and widespread. Here Randal gathers together all the tidbits you really ought to know about creating a distribution. This covers <code>h2xs</code>, documentation (POD), the <code>MANIFEST</code>, <code>Makefile.PL</code> and testing (an absolute must). Then once you've covered all that ... finally make dist :)
Essential Testing looks at a few of the obvious testing modules and emphases their usefulness. It should be bourne in mind that basic testing should be the very least you do for a distribution, but the more complex a distribution the more thorough the tests should be. This chapter is just a starting point and it is an exercise for the reader to take it further.
The final chapter, Contributing To CPAN, looks at preparing your distribution for CPAN. It seems the exercise in this chapter has raised more interested than the rest of the book. If someone like Alan Turing can't solving the halting problem, I sincerely doubt anyone in the midst of learning Perl with this book is going to solve it. If anything, I felt the tone of the chapter was very positive and tried to impress upon the reader the value that CPAN holds within the community. My only comments about the chapter, would be to include references to the Module Authors mailing list, and the importance of getting feedback from the community whether that's on one the many mailing lists or somewhere like Perl Monks.
I found the exercises in the book to be thought provoking without stretching the reader too far, each building on what was discussed in the chapter and the previous exercise. All the answers to the early exercises are included in the Appendix, although it should be noted that the halting problem isn't included :).
The book is a good collection of chapters to help you understand Perl modules, packages and distributions. Well paced, taking you from some basic ideas, to some quite intricate Perl idioms. The book is very much aimed at the novice Perl programmer, although I suspect anyone else could pick up a thing or two.
We are one of the UK's largest Perl user groups, representing Birmingham UK to the international Perl community since 2000. We hold monthly social and technical presentations, and several of our members are now regular attendees and speakers at the YAPC::Europe Perl Conferences.
For further information about Birmingham.pm, please read our Frequently Asked Questions page.
For details about joining our mailing list, please Click Here for more details.
No meeting currently scheduled
13 Jan - Brum.pm Social
10 Feb - Brum.pm Social
9 Mar - Brum.pm Social
13 Apr - Brum.pm Social
11 May - Brum.pm Social
8 Jun - Brum.pm Social
13 Jul - Brum.pm Social
Download the Birmingham.pm ICalendar
or subscribe to our Google Calendar
Aberdeen Perl Mongers
Bath Perl Mongers
Birmingham Perl Mongers
Bristol Perl Mongers
Devon & Cornwall Perl Mongers
Edinburgh Perl Mongers
Glasgow Perl Mongers
London Perl Mongers
Milton Keynes Perl Mongers
North of England Perl Mongers
Nottingham Perl Mongers
Southampton Perl Mongers
Thames Valley Perl Mongers
• Linux System Programming
• Mastering Perl
• GIMP 2 for Photographers
• Minimal Perl
• Wicked Cool Perl Scripts
• Red Hat Linux 9 Unleashed
• IRC Hacks - 100 Industrial-Strength Tips & Tools
• eBay Hacks - 100 Industrial-Strength Tips & Tools
• Exploiting Software - How To Break Code
• Mac OS X Unleashed, 2nd Edition
* New Reviews
.. More Reviews