use autodie

| 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

Clojure one-liner
I am convinced that the new programming language called Clojure has alot of potential and if successful will fundamentally ... »
Trusting yourself
An excellent book that I've been reading is called Management 3.0 by Jurgen Appelo. The book has all kinds ... »
Remembering and then forgetting
There is that last fleeting moment right before you fall asleep when your mind empties of all thought and ... »
Zuma
Being stuck in the middle of a huge traffic jam just south of Amsterdam is no fun, especially when ... »
Running in the cold
Most people of sound mind would find it extremely difficult to understand that inner urge of mine which keeps ... »