Scarborough has asked for the wisdom of the Perl Monks concerning the following question:

I have read that using exit 1; is an exceptable way of exiting from a program however when I've done something like this
#in first_prog.pl #do something wrong exit 1;
and then in a second program
$result = system "perl first_prog.pl" print $result; #I get 256
I've read somewhere that exit cannot be relide upon but why?

Replies are listed 'Best First'.
Re: Exit with a number
by gellyfish (Monsignor) on Aug 03, 2004 at 14:21 UTC

    That 256 is correct - you need to print $result >>8 to get rid of the first eight bits of the number which are put there by the OS

    /J\

Re: Exit with a number
by sweetblood (Prior) on Aug 03, 2004 at 14:27 UTC
    from perldoc -f system

    The return value is the exit status of the program as returned
    by the "wait" call. To get the actual exit value divide by 256.

    Sweetblood

Re: Exit with a number
by mifflin (Curate) on Aug 03, 2004 at 15:48 UTC
    System's return value has a lot of information in it.
    $exit_value = $result >> 8; $signal_num = $result & 127; $dumped_core = $result & 128;
Re: Exit with a number
by Your Mother (Archbishop) on Aug 03, 2004 at 23:57 UTC

    I think it's a holdover from shell stuff. "0" is really the non-error, non-problem exit code. All the integers indicate something that needs attention (and the messages are different by OS/environment). perldoc -f exit for more.