Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handling Constructs? 1

Status
Not open for further replies.

drkestrel

MIS
Sep 25, 2000
439
GB
I have code like the following
Code:
#$cmd is some UNIX command like the following
$cmd = "cp abc 123";
open (EXP,$cmd) 
        or ????????????????
while (<EXP>) 
{
    $output .= $_;
}
close EXP;

my question is with the ???????
I want to do a few things to clean up and not just 'die'....
How could I 'do more than one thing' within the or ???????
If you see what I mean? (they are fairly trivial, so don't think a subRoutine is neccessary?)

 
Can't you just use a block,

or {
stmt1;
stmt2;
}

I think you can

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
Yes, you should be able to use a block, or even a sequence of commands separated by commas might work. But, why do you think a subroutine is unnecessary just because what you would be doing in it is trivial? Subroutines are often used to help clarify and modularize code, even when what's being done in them is trivial. If you're worried about overhead remember that the subroutine will only be called for the exception, so it shouldn't happen that often. In addition, if you build the subroutine properly you could make it work for several different situations, perhaps passing it a parameter to tell it which situation to handle.

In sum, never rule out using a subroutine just because what's being done in it is &quot;trivial&quot;.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Oh, if you do decide to use a block you might have to say &quot;or do { statements }; Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top