Getting return code to shell
han_perl
created: 2004-06-14 21:25:35
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
created: 2004-06-14 21:34:05

You want [exit]. I'd do it like this,

my %exit_code = {
    PASSED  => 0,
    FAILED  => 1,
    ABORTED => 2
);
# ...
exit $exit_code{$STATUS};

After Compline,
Zaxo

Re^2: Getting return code to shell
created: 2004-06-15 00:17:54
or even:


use constant {
	PASSED	=> 0,
	FAILED	=> 1,
	ABORTED	=> 2,
};

# then use:
exit PASSED;
exit FAILED; #etc

perlmonks.org content © perlmonks.org and han_perl, meetraz, Zaxo

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03