in reply to style for returning errors from subroutines

Think about it as most perl defaults do it, as well as the various common modules.

open FILE, ">file.txt" or die $!;
Here, the OS error is shuffled into the $! global, which is specifically there to hold perl-level errors.

my $sth = $dbi->prepare("SELECT * FROM TABLE") or die DBi->errstr;
Again, while not storing the error in a global, it does store it in a package-level variable, and that value is only changed when there is an error. You still get back useful returns from the call (an sth object or undef).

So I'd say the best way to do it is to make sure you use packages and for each one, create a package-level variable that is to store any error messages. Then your functions should return any defined value if no error occured, or undef if one did, then you can use the typcal  $var=function() or die $msg pattern above. The only gotcha to all this is if 0 or '' is a valid return from a function in addition to undef, in which case you might have to handle the checking via  defined($var=function()) or die $msg.


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain