http://www.perlmonks.org?node_id=1072553

gri6507 has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I have two script, main and helper, where the latter is executed by the former using a do() statement. I would like to do something on abnormal terminations of the helper. I tried using an END {} block withing the helper to do that, but unfortunately it seems to only execute on completion of the main script.

Here is my main script

use warnings; use strict; my $doItScript = $ARGV[0]; unless (my $return = do $doItScript) { if ($@) { print "$doItScript: $@\n";} elsif (!defined($return)) { print "$doItScript: $!\n";} elsif (!$return) {print "could not execute $doItScript\n";} } print "Done with main\n";

Here is my helper script

use warnings; use strict; use Carp; END { print "Good bye\n"; } print "Hello\n"; croak "bad thing"; print "There\n"; 1;

As expected, the helper "There" message is not printed, but the "Good bye" message is printed only after "Done with main". How can I reverse the order of those two events?