in reply to Completely Useless
Hey, you know what'd be neat? To customize the
error message. Sure, it's still just as useless, but
that's okay. So here's the new version:
Usage is the same as before, but if you want an extra special output function, try this:package Silly::Die; use strict; use vars qw/$OUTPUT/; sub import { my $class = shift; my $caller = caller; no strict 'refs'; *{"${caller}::trying"} = \&{"${class}::trying"}; $OUTPUT = shift if @_ && ref $_[0] eq "CODE"; } sub trying { $OUTPUT ? $OUTPUT->($!) : $! } 1;
Prints:use Silly::Die sub { qq(I died with: "@_") }; open FILE, "foo" or die trying;
I died with: "No such file or directory" at ./test.pl line 9.
In Section
Cool Uses for Perl