Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Managing errors in subroutines

by Bilbo (Pilgrim)
on Apr 16, 2003 at 09:48 UTC ( [id://250825]=note: print w/replies, xml ) Need Help??


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
    Yes, I forgot to specify that here are many other instructions between them. However, thank you for your comment.
    Roberto

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://250825]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found