diff options
author | Doug Bell <madcityzen@gmail.com> | 2015-11-24 02:31:38 -0600 |
---|---|---|
committer | Ricardo Signes <rjbs@cpan.org> | 2015-12-07 11:18:57 -0500 |
commit | 7cf4dd3e4ab14124f5e2946c4ccfba595dd9d760 (patch) | |
tree | a04dba15efcb0b8540492f15c3c9e4cb819d64e6 /pod/perlop.pod | |
parent | f67a500207b5795952c02ea7b3c1af93098433fb (diff) | |
download | perl-7cf4dd3e4ab14124f5e2946c4ccfba595dd9d760.tar.gz |
mention $? in backticks documentation
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.
Diffstat (limited to 'pod/perlop.pod')
-rw-r--r-- | pod/perlop.pod | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/pod/perlop.pod b/pod/perlop.pod index 16916144d7..50ee6e0bfc 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -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>/> |