in reply to if and else
The differences you see come about because or takes precedence over if. Because of this, or doesn't act like "else". Instead it turns its neighbors into a single condition used by if. If you put in parenthesis to explicitly show precendence, the two statements you wrote above look like this:
print "TRUE" if (0 or die "FALSE"); print "TRUE" if (0 or print "FALSE"); #or alternatively if (0 or die "FALSE") { print "TRUE"; } if (0 or print "FALSE") { print "TRUE"; }
Once you see the precedence, the difference in behavior is obvious: when 0 or die "FALSE" gets evaluated it dies before ever getting to what is inside of if {...}. On the other hand, 0 or print "FALSE" evaluates to true and causes Perl to enter inside of the if {...} statement. Hence, "FALSETRUE" gets printed.
Best, beth
|
|---|