Yes, that appears to be what's happening:
C:>perl -le "sub u { unless(shift) { 'false' } }; print u($_) for unde
+f, '', 0..3"
false
false
false
1
2
3
C:>perl -le "sub i { if(shift) { 'true' } }; print i($_) for undef, ''
+, 0..3"
0
true
true
true
I'm not sure if it's meeting the technical definition of "expression" from "If no return is found and if the last statement is an expression, its value is returned"... but the last statement executed was the failed if or unless, and as part of that execution of that statement, the CONDITIONAL expression had to be evaluated, so I can definitely see a good case for why that EXPR's value is what is returned. But since I couldn't find a perl-specific definition of "expression" (and it appears it's been a longstanding lack of definition, because as far back as 2001, people were asking What is the difference between a Statement and an Expression? without getting a canonical answer from the perl documents), there is wiggle-room in the interpretation of whether the documents claim the return value is unspecified or not.
Interesting sub-discussion. Thanks! |