in reply to Warning while using ternary operator
The ternary operator is not a shorthand way of writing an if block. It's a shorthand way of writing an if block that returns a value.
if ($expression) { $var = "foo"; } else { $var = "bar"; } # WRONG $expression ? $var = "foo" : $var = "bar"; # correct $var = $expression ? "foo" : "bar";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Warning while using ternary operator
by kcott (Archbishop) on Dec 16, 2013 at 15:19 UTC | |
by AnomalousMonk (Archbishop) on Dec 16, 2013 at 23:15 UTC |
In Section
Seekers of Perl Wisdom