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

In reply to Re: Kindly let me know what exactly && does in Perl by ikegami
in thread Kindly let me know what exactly && does in Perl by pritesh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.