It is difficult for me to bottom post as I am using Lnotes.  Sorry.

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.

Finally, when do I use my $exval = $? >> 8 as opposed to my $exval = $? >>
127.  And what is the diff?

almost!
thanks



                                                                           
             "Wiggins                                                      
             d'Anconia"                                                    
             <[EMAIL PROTECTED]                                          To 
             .org>                     [EMAIL PROTECTED]              
                                                                        cc 
             02/28/2005 10:09          Perl Beginners <beginners@perl.org> 
             AM                                                    Subject 
                                       Re: return code                     
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




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>


Reply via email to