in reply to Re: strange boolean algebra behaviour
in thread strange boolean algebra behaviour

use strict; use warnings; my $a = 1; my $b = 0; my $c = $a and $b; print "c=$c\n";
This gives me warning that "Useless use of private variable in void context at tmp16.pl line 6.". line 6 is "my $c = $a and $b;". I first tried -MO=Deparse.
C:\temp>perl -MO=Deparse tmp16.pl Useless use of private variable in void context at tmp16.pl line 6. use warnings; use strict 'refs'; my $a = 1; my $b = 0; $b if my $c = $a; print "c=$c\n"; $a = 1; $b = 0; $c = $a && $b; print "c=$c\n"; tmp16.pl syntax OK
So, Deparse maybe says $b of "$b if my $c = $a;" is the useless use of private variable.
regards.

Replies are listed 'Best First'.
Re^3: strange boolean algebra behaviour
by Anonymous Monk on Apr 05, 2012 at 06:54 UTC

    -p

    $ perl -MO=Deparse -e " my $foo = $bar and $baz; " $baz if my $foo = $bar; -e syntax OK $ perl -MO=Deparse,-p -e " my $foo = $bar and $baz; " ((my $foo = $bar) and $baz); -e syntax OK
      When you use the -p option, the output also includes parentheses even when they are not required by precedence, which can make it easy to see if perl is parsing your expressions the way you intended.

      thank you. maybe easier to see.

      perl -MO=Deparse,-p -anle "print $F[3];" tmp.txt
      This showed me what is -a,n,l.