Posted by brian d foy on January 31, 2010
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, [...]
Posted by brian d foy on January 24, 2010
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, $/ [...]
Posted by brian d foy on January 17, 2010
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 [...]
Posted by brian d foy on January 12, 2010
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 [...]
Posted by brian d foy on January 8, 2010
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 [...]
Posted by brian d foy on January 5, 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 [...]
Posted by brian d foy on January 5, 2010
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 [...]
Posted by brian d foy on January 1, 2010
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)