Please bottom post...
[EMAIL PROTECTED] wrote:
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,
0 is true and non-zero is false in this context, it is opposite of Perl, is that the confusion?
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";
Wrong statement, if ($exval == 0) is testing for true not false.
}else{ exit; } } } print "line count is: $. \n"; close (F);
derek,
Did this get it?
http://danconia.org
[snip for chris ;-)]
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>