in reply to Perl exception - multiple statement

In order to escape from the eval block, you need to tell Perl something unexpected has occurred. This usually done with die, where you should check $? after each system command, a la:

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
    Note that just "solution" doesn't give you the actual error message. Just information about the exit value, the signal that terminated the child, and whether core was dumped.