Is there a way to set my own return code back to the shell?
####################################################
#main program "junk.pl"
$STATUS = "FAILED";
print "just a return code test to the shell\n";
if ( $STATUS eq "PASSED" ){ return 0; }
elsif ( $STATUS eq "FAILED" ){ return 1; }
elsif ( $STATUS eq "ABORTED" ){ return 2; }
else { return 3; }
##################################################
I would like it to return the return code back to the shell. Then do a echo $? to get the number I specified.
This is the output of the above program:
$ perl junk.pl
just a return code test to the shell
Can't return outside a subroutine at junk.pl line 8.
Thanks.
Re: Getting return code to shell
You want [exit]. I'd do it like this,
my %exit_code = {
PASSED => 0,
FAILED => 1,
ABORTED => 2
);
# ...
exit $exit_code{$STATUS};
Re^2: Getting return code to shell
or even:
use constant {
PASSED => 0,
FAILED => 1,
ABORTED => 2,
};
# then use:
exit PASSED;
exit FAILED; #etc