Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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,
Zaxo


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2015-07-02 01:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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









    Results (25 votes), past polls