in reply to Managing errors in subroutines
Well, you could do something like this:
sub test_sub { my $error_msg = sub1() || sub2() || sub3(); return $error_msg; }
This works because (quoting from perlop) "Binary "||" performs a short-circuit logical OR operation. That is, if the left operand is true, the right operand is not even evaluated", so $error_msg will contain the first non-zero return value or zero if all subs are successful, and no more subroutines are called after one has returned a non-zero value.
Of course, if your program does other things between each subroutine call then this won't help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Managing errors in subroutines
by rbi (Monk) on Apr 16, 2003 at 09:55 UTC |