The problem is that and has very loose precedence, looser than the assignment operator. So you need to write $a && $b or ($a and $b). See perlop for more details.
In Perl 5, the false value is represented as an empty string that can numify to 0 without a warning. That's what you are seeing in your second attempt.
In reply to Re: strange boolean algebra behaviour
by moritz
in thread strange boolean algebra behaviour
by vlad_tepesch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |