Syntactic Confectionery Delight | |
PerlMonks |
Re^2: ternary operator as lvalue failing to induce evaluation of right-hand expression in list contextby Athanasius (Archbishop) |
on Aug 04, 2013 at 08:05 UTC ( [id://1047774]=note: print w/replies, xml ) | Need Help?? |
Deparse shows that the parentheses in the OP are unnecessary, which is as expected, since the conditional operator ?: has a higher precedence than assignment (see Operator Precedence and Associativity). Consider:
Output:
It’s clear that foo is being evaluated in scalar context, even though the condition evaluates to true and so chooses the LHS. Since foo would still be evaluated in scalar context if the condition were false and the RHS chosen, it’s now clear why the compile error has disappeared: it is known at compile time that foo will be evaluated in scalar context. But that leaves us with some unanswered questions:
I have the feeling that there’s an obvious answer to all this, but I can’t see it. Which is, just possibly, related to the fact that in my neck of the woods the Ashes coverage finishes around 3:30 am... |-O
In Section
Seekers of Perl Wisdom
|
|