This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mention $? in backticks documentation
authorDoug Bell <madcityzen@gmail.com>
Tue, 24 Nov 2015 08:31:38 +0000 (02:31 -0600)
committerRicardo Signes <rjbs@cpan.org>
Mon, 7 Dec 2015 16:18:57 +0000 (11:18 -0500)
Backticks work like system(), in that they use $? for the child exit
code. Mention that so people know to look in $? when their program
fails.

pod/perlop.pod

index 1691614..50ee6e0 100644 (file)
@@ -2309,6 +2309,21 @@ when they're the right way to get something done.  Perl was made to be
 a glue language, and one of the things it glues together is commands.
 Just understand what you're getting yourself into.
 
+Like C<system>, backticks put the child process exit code in C<$?>.
+If you'd like to manually inspect failure, you can check all possible
+failure modes by inspecting C<$?> 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;
+    }
+
 See L</"I/O Operators"> for more discussion.
 
 =item C<qw/I<STRING>/>