Book Review: Perl Best Practices
We all have done it, haven't we? We've looked at source code--either our own or someone else's--and asked that age-old programming question: "What is this code doing?". When code is written in Perl, the aforementioned question probably is uttered more than it needs to be, as Perl--the ever-popular duct tape of the Internet--often is used to produce code that is hard to understand. This problem is exasperated by the Perl community's near obsession with letting programmers work in whatever way suits them. Although the Perl motto, "There's more than one way to do it", often can be a strength, it also can work against large projects and team efforts. This may be especially true if every team member's code is a law-unto-itself when it comes to style, coding standards, layout and idioms used. Typically, if this is the case, you end up with a Perl code base that is unmaintainable.
In tackling this problem head-on, Damian Conway is nothing if not brave. In his latest book, Perl Best Practices, Damian attacks subjects that should be close to the heart of every Perl programmer: coding standards, styles and development practices and behaviors. In 500 pages or so, Conway presents what he believes to be a consistent set of standards and styles for developing maintainable code when using Perl. Almost magically, there are 256 of these guidelines in the book, offering help to Perl programmers of every ability.
Conway's bravery comes from his decision to highlight the problems that programmers can get themselves into when programming in Perl. Typically, these problems are with Perl as opposed to the programmer, and there's plenty of criticism of the programming language adored by the majority of Conway's readership. Conway's saving grace is that, having criticized, he then proceeds to demonstrate a technique or practice for avoiding that which he criticized. Make no mistake, some of Conway's advice is controversial. Indeed, the outright banning of unless is highlighted by Conway himself as potentially raising a few eyebrows. And, there's plenty of other guidelines that will produce gasps and grunts from many a Perl programmer. As an example, consider the "Don't use bareword filehandles" guideline from the start of Chapter 10, which warns against writing code such as this:
open FILE, '<', $filename
or croak "Can't open '$filename': $OS_ERROR";
If you are reading this and wondering what's wrong with the above code, don't despair. On the surface, nothing is too wrong with the code, as it does indeed open a file and assign it to a filehandle. What can happen, though, is this innocent-looking code can lead to problems when systems grow to anything larger than a 20-line throw-away script. It is more robust, reliable, efficient and maintainable to rewrite the above code using an indirect filehandle, like so:
open my $FILE, '<', $filename
or croak "Can't open '$filename': $OS_ERROR";
Why it is important to do this is covered in detail by Conway. After reading his reasoning, it is hard to argue against or ignore what's being advised, even though every other Perl book I've ever seen--including mine--open files using a bareword filehandle. Of course, it is at times such as this that Conway's advice and explanations become invaluable. By describing the awfulness that can result from not adhering to the guidelines and then following up with a robust solution, many a late-night or multi-day debugging session can be avoided. Programmer sanity is, without a doubt, something to strive for and maintain. It is clear that one of Conway's main goals in writing this book is to keep you and others that read your code sane by steering the programmer away from many of Perl's pitfalls.
While working through the book, I learned a lot about the current problems with Perl 5. I found myself constantly reciting the same prayer, "Oh my, please let them fix that in Perl 6." All indications within Perl Best Practices say that these things will be fixed. However, as Perl 5 will be around for quite some time, Conway's book has real value now that will only increase as time goes by. Even when Perl 6 does arrive, the majority of the guidelines will remain valid and should continue to be followed.
Of interest is the long list of technical reviewers thanked at the start of the book: it includes some of the biggest names in the Perl world. So Perl Best Practices is not simply Conway's best practices, but the best practices actually practiced by the inner circle that Conway identifies.
One small gripe is I wish the guidelines had been numbered, for ease of reference. Nice touches include the decision to highlight "good code" in bold mono throughout the text and "bad code" in regular mono. The book also provides plenty of references to supporting material on the Web. The jokes, when they come, often are something special.
As all Perl programmers know, there's an awful lot to Perl, and there's an awful lot of Perl to learn. In addition to covering the essential material, Conway's book discusses some of the darker recesses (features?) of Perl that I've never seen covered anywhere else. By working through Perl Best Practices, you will become a better Perl programmer, even if you decide not to adopt the guidelines offered to you. From my own point of view, I'd like to see a CPAN icon that indicates whether a submitted module conforms to Conway's 256 guidelines. I'd like to build my future applications using shared modules that I know I'll be comfortable reading, amending and working with.
For now, I'm off to update my Perl Tutorial to conform to Conway's guidelines. I'm also looking forward to the first official release of Perl 6. Damian Conway's Perl Best Practices is a must-have.
Paul Barry lectures at the Institute of Technology, Carlow, in Ireland. He is the author of two textbooks that use Perl. He can be contacted at paul.barry@itcarlow.ie.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- New Products
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- seo services in india
4 hours 18 min ago - For KDE install kio-mtp
4 hours 19 min ago - Evernote is much more...
6 hours 19 min ago - Reply to comment | Linux Journal
15 hours 4 min ago - Dynamic DNS
15 hours 39 min ago - Reply to comment | Linux Journal
16 hours 37 min ago - Reply to comment | Linux Journal
17 hours 27 min ago - Not free anymore
21 hours 29 min ago - Great
1 day 1 hour ago - Reply to comment | Linux Journal
1 day 1 hour ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
0www
thanks bro nice article Paul Barry
"i hate micr0z0rt :D"
Nice book
Nice book :)
search
nice book
A must-read for any Perl programmer
Covering the sections other Perl books do not cover..
Great Help.....
Thanks
Good and Informative
Nice work.. Good and Informative book ..
Useful resource
I found the book to be an interesting read, and certainly worth a look. While in The Real World I'm still guilty of ignoring some of these best practices, reading this has certainly improved the quality of my code.
?
Is this journal hosted by wordpress?
Comment
Interesting article
Very good book
This is the book that tells you how to do things until you gain enough experience to know how to do them. Then you'll do them as described in this book because the way described is so good.