[DOC PATCH] Re: [perl #23779] $? and negative exit codes
Dave Mitchell [Tue, 16 Sep 2003 21:56:20 +0000 (22:56 +0100)]
Message-ID: <20030916205620.GB1246@fdgroup.com>

p4raw-id: //depot/perl@21253

pod/perlfunc.pod

index d7a3fa4..fff672b 100644 (file)
@@ -5745,9 +5745,17 @@ your program.
 You can check all the failure possibilities by inspecting
 C<$?> like this:
 
-    $exit_value  = $? >> 8;
-    $signal_num  = $? & 127;
-    $dumped_core = $? & 128;
+    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;
+    }
+
 
 or more portably by using the W*() calls of the POSIX extension;
 see L<perlport> for more information.