in reply to Perl exception - multiple statement
eval { system("cp xyz.dat abc.dat"); die "$?\n" if ($?); system("cp xyz.dat2 abc.dat2"); die "$?\n" if ($?); }; if ($@) { print "Error occured: $@\n"; }
Please note the difference in reliable scoping between $? and $@ - as noted in Error Indicators.
Update: As JavaFan notes, this does not capture the actual error messages, only the error codes returned from system (as per your OP). If you want to handle the actual error messages, you'll need to capture STDERR, as per 781684.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Perl exception - multiple statement
by JavaFan (Canon) on Jul 20, 2009 at 16:42 UTC |