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

A walk along the Keizersgracht
Too often one is so consumed by a jungle of intertwined thoughts that the beauty of the nearby surroundings ... »
Popularity is fickle
The popularity of a given next generation technology is very fickle, and its success or failure depends on many ... »
Where was Kiffin really buried?
Hi There seems to be some confusion on the current resting place of Kiffin Rockwell, some say that his ... »
Going to Portugal
Normally the week just before I leave for summer vacation, I spend hours on end desperately searching for some ... »
A human language
These days it is not very often that a new and exciting Perl book comes along. That's why I ... »