in reply to Ternary vs. Sort vs. Max
Just for the sake of TIMTOWTDI:
$max = ($x,$y)[$x<$y]; $min = ($x,$y)[$x>$y];
which is a golfed version of your 2nd variant: (sort-of) a one-step sort which eliminates building a code block frame and the call of sort. Ternary is cheaper, since it doesn't involve bulding a list.
update:
I've been working at a place where restrictive coding standards prohibited ternary and forced me to write
if ($x < $y ) { $max = $y; } else { $max = $x; }
- which is as cheap as ternary (I guess) but looks convoluted to me - among other hilarities. Good riddance.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Ternary vs. Sort vs. Max
by fullermd (Priest) on Aug 11, 2015 at 04:25 UTC |
In Section
Meditations