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


in reply to Finding the max()/min()

Here's a pair I like, similar to your delightfully symmeteric third example,

# max my $max = ($x, $y)[$x < $y]; # min my $min = ($x, $y)[$x > $y];
Those are slightly forthish, in lifting a logical value to arithmetic use.

Update: As subroutines,

sub max ($$) { $_[$_[0] < $_[1]] } sub min ($$) { $_[$_[0] > $_[1]] }
I used prototypes there because the usual perl min and max extracts the extreme of a list, instead of from just two values.

After Compline,
Zaxo