Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Finding the max()/min()

by Zaxo (Archbishop)
on Nov 11, 2004 at 02:38 UTC ( #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,

Comment on Re: Finding the max()/min()
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2015-07-31 01:52 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (274 votes), past polls