return if 0by zigdon (Deacon)
|on Jun 22, 2009 at 17:36 UTC||Need Help??|
zigdon has asked for the wisdom of the Perl Monks concerning the following question:
Perlsub talks about subroutine return values:
Based on that, I thought I understood subroutine return values - but now I'm not sure anymore. Consider the following:
Running this, I get:
in test! falseWhich made sense to me - we're returning an empty list, which is false. Fine.
But I expected the behaviour to be flipped if I change the 1 to 0. Since 'return if 0' doesn't fire, we don't have an explicit return value, and so the sub should evaluate to the whatever the last statement that executed evaluated to - in this case, the print, which should be true.
But that wasn't what happened at all. I had to *comment out* the 'return' line to get the true value I was expecting.
So what am I missing here? Does the 'if' line count as a statement that evaluates to false?