Silly::Die - Who needs punctuation variables?
Published at: 2000.08.18 23:38:38
Silly::Die - Who needs punctuation variables?
use Silly::Die;
EXPR or die trying;
Silly::Die is completely useless, but that shouldn't stop you from using it.
Instead of dying with a nasty punctuation variable ($!), you can now die with a simple, common English phrase: ``die trying''.
What could be simpler?
Thus writing
open FH, "foo" or die $!;
translates to
open FH, "foo" or die trying;
Looks much better.
In addition, you can even customize the output of the
trying function. When you load the module (with a
use statement), pass in a subroutine reference. When you call trying, your sub reference will be invoked and passed the contents of $!. You can return anything you want, which will be then passed back to die. For example:
use Silly::Die sub { qq(I died with: "@_") };
open FILE, "foo" or die trying;
This prints out
I died with: "No such file or directory" at ./test.pl line 9.
This is, of course, completely useless.
Benjamin Trott, ben@rhumba.pair.com
© 2000 Benjamin Trott, ben@rhumba.pair.com