in reply to Re: Boolean (was Boolian) operators defy my understanding...
in thread Boolean (was Boolian) operators defy my understanding...

ikegami...

I appreciate your comments and example code.

I also have also found similar code (http://perldoc.perl.org/functions/system.html):

You can check all the failure possibilities by inspecting $? like this:

if ($? == -1) { print "failed to execute: $!\n"; } elsif ($? & 127) { printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without'; } else { printf "child exited with value %d\n", $? >> 8; }

I'm curious as to what determines the use of 127 and 128 in this script, and what is meant by "$? >> 8"?

Thanks!

Replies are listed 'Best First'.
Re^3: Boolean (was Boolian) operators defy my understanding...
by ikegami (Patriarch) on Jun 21, 2007 at 17:33 UTC

    I'm curious as to what determines the use of 127 and 128 in this script

    The format of system's return value.

    system returns either -1, or a (at least) 32-bit value composed of three fields.

    bit F E D C B A 9 8 7 6 5 4 3 2 1 0 +---------------+-+-------------+ |xxxxxxxxxxxxxxx|c|sssssssssssss| +---------------+-+-------------+
    • s: Signal that caused the child to exit or 0 if the child existed normally.
    • c: A core dump was produced if 1.
    • x: Child's exit code (if s is zero).

    what is meant by "$? >> 8"?

    Perl operators are documented in perlop.