|Think about Loose Coupling|
Re^2: Warning while using ternary operatorby kcott (Canon)
|on Dec 16, 2013 at 15:19 UTC||Need Help??|
This is bad information.
is only "# WRONG" because of operator precedence (see perlop: Operator Precedence and Associativity). Here's how it is parsed:
This is explained in perlop: Conditional Operator. Correcting the precedence with parentheses:
I do not dispute that '$var = $expression ? "foo" : "bar";' is a better way to write '$expression ? ($var = "foo") : ($var = "bar");'. In fact, the documentation also recommends this.
Once corrected as indicated, here's how your "# WRONG" code behaves: