Christmas brings the RJBS Advent Calendar

*By Ricardo Signes*
Back when I first started learning Perl 5, I was excited to find the [Perl
Advent Calendar](http://perladvent.pm.org/archives.html). It was a series of
24 or so short articles about useful Perl modules or techniques, with one new
entry each day leading up to Christmas. A few years later, the Catalyst crew
started the [Catalyst Advent
Calendar](http://www.catalystframework.org/calendar/2005). I always liked
the Perl Advent Calendars, and kept meaning to contribute. Every time,
though there were too many things I’d want to write about — and mostly they
were my own code, so I felt sort of smarmy and self-promoting and never did
it.
Finally, though, I’m glad to say I have tackled those feelings. I will not
shy away from showing off my own code, and I will not worry about having to
choose just one thing. This year, I will publish the [RJBS Advent
Calendar](http://advent.rjbs.manxome.org/), 24+ full days of cool, useful, or
stupid code that I have written and given as a gift to the rest of the CPAN
community.
I’ve had a lot of fun working on this project, and it’s helped me find and
fix a number of little bugs or imperfections in the software I’ll be talking
about.
The first door opens in seven days. I hope it’s as fun to read as it was to
write. No returns will be accepted. Approximate actual cash value: $0.02
*Ricardo Signes has written [tons of modules on the CPAN](http://search.cpan.org/~rjbs/), including [Dist::Zilla](http://search.cpan.org/dist/Dist-Zilla/), the heir apparent to Module::Starter. He is also a total sweetheart, and has a fuzzy head.*

Perl gets modern community blogging platform at blogs.perl.org

In a move of unparalleled beauty, Dave Cross and Aaron Crane have announced [blogs.perl.org](http://blogs.perl.org), a modern blogging platform for the Perl community.
Go look. Enjoy the non-ugly color scheme. Marvel at the code syntax highlighting and ability to embed images. Navigate posts using thoughtful categories.
A million thanks to Dave and Aaron for putting this together, and to [Six Apart](http://sixapart.com) for the design. Links to feeds will be going up here on Perlbuzz as soon as I have time.

Perlbuzz news roundup for 2009-11-17

These links are collected from the
Perlbuzz Twitter feed.
If you have suggestions for news bits, please mail me at
andy@perlbuzz.com.

  • Pod::Simple 3.09 hits the CPAN (justatheory.com)
  • Strawberry Perl and the nightmare of installing Padre (use.perl.org)
  • A busy month for masak in Perl 6 (use.perl.org)
  • A productive week in Rakudo-land (use.perl.org)
  • Perl one-liners explained part III: Calculations (catonmat.net)
  • Handy one-liner to lowercase all filenames in a directory: ls | perl -lne’$x=lc;print qq{mv $_ $x}’ | sh -x
  • Use CPAN’s toolchain to improve your code (use.perl.org)
  • Future Perl snuck up on me (headrattle.blogspot.com)
  • Find the stupid bug in my progress indicator: say “$n so far” if ( $n % 100000 )”;
  • I maeked u a shell: lolshell, written in Perl 6 (theintersect.org)
  • The horrible bug your command line Perl program probably has (perlbuzz.com)
  • Frozen Perl 2010 looking for speakers (news.perlfoundation.org)
  • apache2rest is a new framework for REST APIs under mod_perl2 (code.google.com)
  • Putting MySQL on a ramdisk to speed up tests (use.perl.org)
  • Generating Feedburner graphs (catonmat.net)

perl.org gets a beautiful upgrade

Robert Spier writes
> To match the massive advances in Perl over the last few years, www.perl.org has been brought into the modern era. [www.perl.org](http://www.perl.org) has been completely redesigned, making it clearer and easier to use. All the content has been reviewed and brought up-to-date to provide links and other helpful resources for both new and experienced Perl programmers.
>
> Thanks to [www.foxtons.co.uk](http://www.foxtons.co.uk) for donating time from Leo Lapworth, Stephen Morgan, and Cameron Richmond!
Holy cow is it pretty. Thanks to those who made it happen! The [download page](http://www.perl.org/get.html) is especially handy.

The horrible bug your command line Perl program probably has

Most programmers know you have to check return values from system
functions. Unless you’re just starting out as a programmer, you
know that this is bad:

open( my $fh, '<', 'something.txt' );
while ( my $line =  ) {
# do something with the input
}

If that open fails the program continues on. The call to
readline will fail, return undef as if we’re at
the end of the file, and the user will be none the wiser. If you
have use warnings on, you’ll get a “readline() on closed
filehandle”, but that’s not much help when you should be dying.
Instead, you should be opening your file like this:

my $filename = 'something.txt';
open( my $fh, '<', $filename ) or die "Can't open $filename: $!";

This way, your user gets a useful error message if something goes
wrong, but more importantly, the program doesn’t continue as if
nothing is wrong, potentially doing what it should not.
h2. GetOptions needs checking, too
Unfortunately, I see programs where otherwise-sensible programmers
ignore the return code of GetOptions.

use Getopt::Long;
GetOptions(
'n=i' => my $count,
);
# Do something that uses $count
print "Processing complete!n";

There are any number of ways the user can call this program incorrectly:

$ perl foo -n
Option n requires an argument
Processing complete!
$ perl foo -n=five
Value "five" invalid for option n (number expected)
Processing complete!
$ perl foo -m=12
Unknown option: m
Processing complete!

In all three of these cases, the user made a mistake, but the program
lets it slide without a mention. The user’s going to be disappointed
with the results.
The solution is simple: Always check the results of GetOptions().
The easiest way is to task && exit(1) after the call:

use Getopt::Long;
GetOptions(
'n=i' => my $count,
) or exit(1);

It’s simple, effective, and prevents unexpected sorrow.