Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

RE: Completely Useless

by btrott (Parson)
on Aug 12, 2000 at 05:45 UTC ( #27599=note: print w/replies, xml ) Need Help??


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:
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;
Usage is the same as before, but if you want an extra special output function, try this:
use Silly::Die sub { qq(I died with: "@_") }; open FILE, "foo" or die trying;
Prints:
I died with: "No such file or directory" at ./test.pl line 9.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://27599]
help
Chatterbox?
[Discipulus]: no erix, was ironic, I could have said Hartz4
[Discipulus]: for sure they had to be in armaic, many reverse-eng errors where spot
[Discipulus]: do you know the google like translation: a rich.. as a camel through the needle hole?
[choroba]: yes, I've read about it and its probable original form

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2017-11-23 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (338 votes). Check out past polls.

    Notices?