Can you please provide good explanation about the following perl code snippet. I got some idea from google but still lots of basic confusion is there. great help if you can provide small notes on it
$exit_value = $? >> 8;
$signal_num = $? & 127;
$dumped_core = $? & 128;
Quoting The Doc:
$?
The status returned by the last pipe close, backtick (`` ) command, successful call to wait() or waitpid(), or from the system() operator. This is just the 16-bit status word returned by the traditional Unix wait() system call (or else is made up to look like it). Thus, the exit value of the subprocess is really ($?>> 8 ), and $? & 127 gives which signal, if any, the process died from, and $? & 128 reports whether there was a core dump.
>> 8
gives us the higher byte of a 16-bit word.
& 127
is essentially the same as & 0b01111111
, giving out the lower 7-bit part of that word.
& 128
is the same as & 0b10000000
, which is basically checking for the 8th bit of the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With