sub DieWithCode { my $numerical_exit_code = shift; my $msg = shfit; # do something with $msg (inserting application name, linebreaks... if necessary exit ($numerical_exit_code); } #### sub DieWithCode { my $numerical_exit_code = shift; my $msg = shfit; # do something with $msg (inserting application name, linebreaks... if necessary if ($^S) { $EXITCODE = $numerical_exit_code; # module global var die ($msg); } print $msg; exit ($EXITCODE); } #### my $e; { local $@; my $result = eval { AppAction (\%opt ) }; if (!defined $result) { # died... $e = $@; printf "result : %s, e : %s\n", defined $result?sprintf "%d", $result: 'undef', $@; } chomp $e; } printf "AppAction failed ($e)\n" if $e; $EXITCODE = 0;