in reply to Re^6: Short form (ternary) if else
in thread Short form (ternary) if else

Adding parentheses to the second statement to show precedence, we get:

( 1 ? ( $x=1 ) : $x ) = 0;

As the 2nd and 3rd arguments are lvalues, you can assign to the ternary operator. As the first argument (1) is TRUE, the assignment becomes:

( $x=1 ) = 0;

Which effectively boils down to:

$ perl -Mstrict -Mwarnings -E 'my $x; ($x = 1) = 0; say $x;' 0

The link I gave above (perlop manpage - under Conditional Operator) has a fuller description.

-- Ken

Replies are listed 'Best First'.
Re^8: Short form (ternary) if else
by gg48gg (Sexton) on Feb 09, 2012 at 00:05 UTC
    Thanks all! I got my question answered and then some. Good discussion.