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

system doesn't return true/false. Please refer to the documentation. For example, if the command was launched successfully and the exit code of the child process is 0, system returns 0.

my $rv = system(...); if ($rv == -1) { die("Unable to launch child: $!\n"); } if ($rv & 127) { die(sprintf("Error executing child: Child died with signal %d, %s c +oredump\n", ($rv & 127), ($rv & 128) ? 'with' : 'without', )); } if ($rv >> 8) { die(sprintf("Error executing child: Child exited with value %d\n", ($rv >> 8) )); } print("Child ran successfully\n");

Replies are listed 'Best First'.
Re^2: Boolean (was Boolian) operators defy my understanding...
by cgmd (Beadle) on Jun 21, 2007 at 17:03 UTC
    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!

      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.