ok so $? states CHILD_ERROR or last status returned by the last ` ....` command. $! states yields the current value of errno
in shell if I say it will give me a true or false value. cat /tmp/foo if [ $? -eq 0 ] then echo yes command succeeded else echo no. fi In Perl if I wanted to represent this I would use $! for any notification of any failures such as opening a file. But when I add the code in red specifically $? >> 8, I get a exit value of 2 and when I change it to $? >> 127 I get a exit value of 0. I want to understand and know the code to get a true (1) or false (0) value. thanks, For this situation assume linect is 3. #!/usr/local/bin/perl -w use strict; use strict 'subs'; my $file = qq(/tmp/mbfree); open (F, "+<$file") or die "unable to open file $file $!\n"; foreach (<F>) { if ( $. < 2 ) { last; } else { print "linect is NOT less than 2: $. \n"; system ("cat /tmp/used"); my $exval = $? >> 8; print "print exit value: $exval\n"; if ( $exval == 0 ) { print "false, file open cat did not happen\n"; }else{ exit; } } } print "line count is: $. \n"; close (F); derek, "John W. Krahn" <[EMAIL PROTECTED] > To Perl Beginners <beginners@perl.org> 02/27/2005 07:59 cc PM Subject Re: return code [EMAIL PROTECTED] wrote: > All, > am I using the correct method to get the return code whether a previous > line or command was 0 false or 1 true? > > > #!/usr/local/bin/perl -w > > use strict; > use strict 'subs'; > > my $file = qq(/tmp/mbfree); > open (F, "+<$file") or die "unable to open file $file $!\n"; > > foreach (<F>) { > if ( $. > 2 ) { > last; > } else { print "return code is: $? \n"; > last; > } > } > print "line count is: $. \n"; > print "return code is: $? \n"; > close (F); perldoc perlvar [snip] $? 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 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. (Mnemonic: similar to sh and ksh.) Since you are not creating a child process, the $? variable does not contain any useful information. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>