in reply to Re: Re: 'and next' question
in thread 'and next' question
You will get 2, which shows that right after "$a++" is evaluated, and before the entire second line finished, ++ already happened.my $a = 1; $a++ and print $a;
Yes, but in your example no short-circuiting occurs. In the original post, the evaluation of the left operand terminates the evaluation of the and so the variable's new value isn't available until "after the and is evaluated".
I guess I could have been more precise. I might have said something like, "the left operand evaluates to undef before being incremented and, since undef is false, the right operand is never evaluated because and is a short-circuit operator." I don't know if that would really have been easier to understand though, even if it is slightly more correct.
At least, instead of "after the and is evaluated" I probably should have said "after the and is short-circuited" or something.
Still, the only reason the and was used in the first place was for its short-circuiting properties. Its return value was ignored. In fact, with your example, if I were being pedantic I wouldn't talk about the and at all...
See? :-)perl -MO=Deparse -e '$a++ and print $a' print $a if $a++; -e syntax OK
-sauoq "My two cents aren't worth a dime.";
|
|---|