use autodie

 | Perl | 0 Comments

So this evening I happened to find out about autodie, thanks to the latest entry in the Modern Perl Books blog by chromatic. Cool stuff.

So I had to run home right away and try it myself, and it works! The following simple snippet:

#!/usr/bin/perl

use strict;
use warnings;

use autodie;
open (my $fh, "<", 'this-file-does-not-exist');
...

generates the following error message:

Can't open 'this-code-does-not-exist' for reading: 'No such file or directory' at x.pl line 8.

No need to waste all that time trying to remember where to stick all those die() statements all over the place (do I use || or do I use or?). So from now on I'll be using autodie just for fun and for work and for play.

Check out Modern::Perl for yourself.

Leave a comment

Recent Entries

Stupid light-pole
Damn. I bashed in the left side of my car against that stupid light-pole while backing out of the ... »
Enjoy life
The man standing next to me was wearing a fancy suit and carrying a leather briefcase in his right ... »
Gale-force winds
"The true (golf) pilgrim wanders off to the outlying, the more humble and obscure courses. For it is on ... »
Secret powers
The front nine was quite a display of supernaturally and (almost) perfectly consistent golfing gusto: Par, par, par, par, ... »
No more winter greens
The cool, windy and grayish afternoon calls me onward. It's drizzling on my windshield but I do not care. ... »