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


in reply to ?: = Obfuscation?

Like most things in perl the ternary operator can both help and hinder readability.

I prefer ternary for this:

# With ternary my $x = exists $hash{key} ? $hash{key} : 'default' # Without my $x; if (exists $hash{key}) { $x = $hash{key}; } else { $x = 'default'; }
I'm on the fence for this:
# With ternary my $x = $x > 5 ? 5 : $x + 1; # With if if ($x > 5) { $x = 5; } else { $x++; }
And dead set against this:
my $x = $y > 5 ? ($y = 0) : ($y = 1);