Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Finding the max()/min()

by Zaxo (Archbishop)
on Nov 11, 2004 at 02:38 UTC ( [id://406885]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://406885]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-19 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found