in reply to Kindly let me know what exactly && does in Perl
Short-circuiting doesn't mean it never evaluates the right operand; short-circuiting means it only evaluates as much as possible to determine the answer. It will still always give the right answer. The truth table for AND is:
false && false => false \ Short circuit possible false && true => false / true && false => false true && true => true
If the LHS is false, it will never evaluate the RHS because of short-circuiting. If the LHS is true, it must evaluate the RHS.
But more importantly, the answer you expect is wrong. True and false shouldn't give true.
Here's a demonstration of short-circuiting in effect.
sub zero { print "zero\n"; 0 } sub two { print "two\n"; 2 } sub three { print "three\n"; 3 } my $x = zero && two; print "\$x is = $x\n\n"; my $y = three && zero; print "\$y is = $y\n\n"; my $z = two && three; print "\$z is = $z\n\n";
zero $x is = 0 <--- two never called three zero $y is = 0 two three $z is = 3
|
|---|