It is difficult for me to bottom post as I am using Lnotes. Sorry.
See previous rants about this.....
ok so yes In general, I thought:
SHELL 0= true Perl 0 = false
SHELL 1 = false Perl 1 = true
what do you mean "non zero is false in this context." b/c in general I thought as above. Yes it is opposite in Perl as above.
But that is not what your test said. What you listed above is correct, but in your code you had:
if ($extval == 0) { print "False...." }
Which is opposite from above.
Finally, when do I use my $exval = $? >> 8 as opposed to my $exval = $? >> 127. And what is the diff?
I am not sure when this changed, but the docs have become IMHO more difficult to read. perldoc -f system describes how to extract the data from $?. Essentially $? encodes using bit switches three values, the exit value of the called program, the signal number that killed it, and whether it dumped core. In older Perl's system's documentation listed that as,
$exit_value = $? >> 8; $signal_num = $? & 127; $dumped_core = $? & 128;
Why this was switched to use the more difficult to read new format wrapped up in an if/elsif/else (with a ternary printf!!) I have no idea. Just *adding* the example would have been a much better idea to me.
So in your case to get the 'exit value' you use the >> 8 shifter and then check for a non-zero value. zero is success, non-zero is failure (in most applications!!! this is only convention!). People often check $? against non-zero/zero because if the program dumped core or exited from a signal the value would non-zero indicating failure. However, it is possible (I suppose) for a program to exit cleanly with an exit value of 0, from either a signal and/or while dumping core, which is why it is "better" to check the exit value. It is also possible for a program to exit successfully with a non-zero value, but it better be documented and I wouldn't suggest doing this (as it breaks convention).
Note that you should not be using, $? >> 127. You need $? & 127 to check the signal number.
almost! thanks
http://danconia.org [snip]
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>