http://www.perlmonks.org?node_id=385190


in reply to Confused by Perl ternary operator

Operator Precedence, again.

A ? B = C : D = E # resolves ( A ? ( B = C ) : D ) = E

So, no matter what A evaluates to, E is being assigned, either to "B = C" (which is the same as assigning to B) or D. In your case B and D are identical, so your ?: operator doesn't do anything useful. Solution:

@_ ? ( $param2 = shift ) : ( $param2 = "Shift" ); # and while we're at it, of course, refactor that $param2 = @_ ? shift : "Shift"

The last line demonstrates why the precedence of "?:" vs. "=" is actually sensible. HTH

--
http://fruiture.de