JTAGGuy has asked for the wisdom of the Perl Monks concerning the following question:
worked fine also when I packed the application using pp (PAR::Packer) into a self-extracting binary. Both under Windows (Strawberry Perl 5.22 ) and Linux (5.22 too). Then I moved the essential part of the code of one application into a sub into a module. Let's call this sub AppAction (parameters) Still everything worked fine. But: In another interactive application (command line, shell like) I want to execute this function WITHOUT the whole program exiting in case of an error where the application packed into the sub would normally exit.sub DieWithCode { my $numerical_exit_code = shift; my $msg = shfit; # do something with $msg (inserting application name, linebreaks... i +f necessary exit ($numerical_exit_code); }
So the function would die in case ofsub DieWithCode { my $numerical_exit_code = shift; my $msg = shfit; # do something with $msg (inserting application name, linebreaks... i +f 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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: PAR::Packer/pp and die/exit
by Anonymous Monk on Apr 01, 2020 at 08:34 UTC |