Mark Henry wrote:
> Hi All,
>
> Anyone know if it's possible for the return/exit value of a script, in the
> event of success, to be something other than 0?
>
> I want to call, from a shell script, a perl script that determines a
> certain
> record ID from a database. When the ID has been obtained, the script
> would exit, and the calling shell script would receive the returned value.
>
> The 'return' command doesn't allow this - I've thought of setting an env
> variable - not sure how to export it from perl so the environment sees it.
> Would like to get plan A to work first though..
>
exit with the status you want or set $? inside END. for example:
#!/usr/bin/perl -w
use strict;
#--
#-- x.pl - does absolutely nothing except handling 10 to the shell
#--
exit 10;
#--
#-- or you could:
#--
=item samething:
END{$?=10}
=cut
__END__
and then in another script:
#!/usr/bin/perl -w
use strict;
#--
#-- y.pl - see what x.pl returns
#--
print system('x.pl') >> 8,"\n";
__END__
prints:
10
the '>> 8' portion removes the lower 8 bits of the returned 16 bit word.
since most os use 16 bit word, your exit value should be 255 or less so if
you do:
exit 12345;
you might not get back what you expect. your os might have larger word size
but Perl might decided to use 16 so it's better to keep it down.
david
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]