go ahead... be a heretic | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I was trying to patch some buggy code when I came across some syntax that I thought was a bit odd and certainly doesn't return results that I expect. Here's the smallest test case I could replicate:
That prints 1, just as I would expect, despite the syntax being a bit odd. However, if I set $x to a false value, it prints 01. Why the heck does it print the zero and then turn around and print the one, anyway? Since print, in this context, should always return a true value, shouldn't this short-circuit and not do both prints? And wouldn't the first print be skipped by the "if $x" check? If I change this slightly:
That only prints "zero". I have an explicit return of false in &zero, but all in all, I'm just not quite grokking this. Cheers, Vote for paco! Join the Perlmonks Setiathome Group or just click on the the link and check out our stats. In reply to Weird syntax question by Ovid
|
|