if ($x < $y ) { $max = $y; } else { $max = $x; }

When faced with the need to write a similar construct (e.g., the condition is too long to make an easily scannable ternary or the like), I find it easier to Just Pick One and then write one conditional, like

$max = $x; if($x < $y) { $max = $y; }

Aside from shorter, I find it actually more descriptive, especially if the other side is an else rather than elseif; "x except when y" as a description reads just like the code.


In reply to Re^2: Ternary vs. Sort vs. Max by fullermd
in thread Ternary vs. Sort vs. Max by QM

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":