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.