What is the meaning of the built-in variable $? in Perl
perl, system
Solution
To find the meaning of any variable, you can either type
$ perldoc -v '$?'
on the command line with relatively recent versions of Perl or scan `perldoc perlvar` installed on your computer. Usually, it is best to read the documentation for the specific version of `perl` you have, but in a pinch, bearing in mind any possible gotchas due to version differences, the online version will do as well: perldoc -v '$?':
The status returned by the last pipe close, backtick (
Further information can be gleaned from the documentation for perldoc -f system:
If you'd like to manually inspect "system"'s failure, you can check all possible failure modes 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; }
While there is nothing wrong with asking even elementary questions on Stackoverflow, if you actually want to become a capable programmer, you'll need to get into the habit of reading the documentation yourself, and develop the capacity to understand it yourself.
Otherwise, you'll waste valuable time you could be using to solve problems instead on waiting for others to read the documentation for you.
It really doesn't affect the rest of us if you choose never to expend any effort in trying to understand documentation, but it will hurt you in the long run.Problem
Possible Duplicate: perl “dollar sign and question mark” question I am trying to understand the Perl script written by someone. I don't understand the use of `$?` in the script. Can anyone explain me the purpose of below line? ``` system( "perform_task.sh", "-param1"); if( ( $? >> 8 ) != 0 ) { print( "perform_task.sh failed " ); } ```