Monthly Archives: January 2010

Know what creates a scope

Scopes can be confusing. Perl 5 introduced lexical, or my, variables that are only visible in the scope in which you define them. To properly scope your variables, you need to know what can define a scope and what doesn’t. You commonly see lexical variables for subroutine arguments, for instance: sub foo { my( $self, [...]

Memory-map files instead of slurping them

The conventional wisdom for slurping a file into a Perl program is to actually load the file into a program. We showed some of these in Item 53: Consider different ways of reading from a stream. There are several idioms for doing it, from doing it yourself: my $text = do { local( @ARGV, $/ [...]

What’s the difference between a list and an array?

I recently updated perlfaq4‘s answer to “What’s the difference between a list and an array?”. The difference between data and variables is often lost of the person who starts their programming career in a high level language. We hit this subject pretty hard in the first chapter of Effective Perl Programming, 2nd Edition in at [...]

Get a review copy of Effective Perl Programming

Addison-Wesley is ramping up its promotion of Effective Perl Programming, 2nd Edition. They’ll send out several free copies to people who like to review books and tell their friends about it. If you’re interested in getting one of those review copies, send me a note at brian.d.foy@gmail.com. If I don’t already know you, introduce yourself [...]

Eliminate needless loops and branching

On Stackoverflow, there’s the question How can I convert a number to its multiple form in Perl?. The best answer for the particular problem is Number::Bytes::Human. Beyond, that, many of the answers take the usual if-elsif-else, such as the one suggested by Michael Cramer: sub magnitudeformat { my $val = shift; my $expstr; my $exp [...]

Effective Perl Programming at Frozen Perl 2010

On Friday, February 5, 2010 at Frozen Perl, I’m teaching a new master class based on our book, Effective Perl Programming, 2nd Edition. The master class is a low-cost, condensed class format given at a public Perl event. The cost of this one-day class is $100, and there are a limited number of $25 seats [...]

Effective Perl Programming, the blog

Josh McAdams and I recently gave Addison Wesley our final manuscript for Effective Perl Programming, 2nd Edition, an update to Joseph Hall’s excellent first edition published in 1998. Not only have we updated the existing material up to Perl 5.10, but we’ve also quite a bit of new material for the evolution of Perl and [...]

Perl 5.8 features

Perl 5.8, mostly a release that improved much of the unseen things in perl, did have some notable, user-visible features. Restricted hashes with Hash::Util (5.8.0) Use sitecustomize.pl to affect all programs (5.8.7) PerlIO is now the default (5.8.0)