Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Clever vs. Readable

by JavaFan (Canon)
on Aug 09, 2008 at 20:57 UTC ( [id://703323]=note: print w/replies, xml ) Need Help??


in reply to Clever vs. Readable

I'd write either:
$min = $a < $b ? $a : $b;
or
$min = $a; $min = $b if $b < $a;

Replies are listed 'Best First'.
Re^2: Clever vs. Readable
by JadeNB (Chaplain) on Aug 26, 2008 at 23:06 UTC
    $min = $a; $min = $b if $b < $a;
    Not only that—if you change $b < $a to $b < $min in the second line, then you're most of the way to addressing the problem with (I think) all the other non-min solutions so far, namely, that they don't handle more than two elements!

    (I sure do love that [ $a => $b ]->[ $b <= $a ] one, though—so much so that, when I heard about it here, I ran out and got Effective Perl just to see if it had more like that. Since the rest of the advice was good, rather than pain-on-the-maintenance-programmer-inflicting, I guess that I have to stick with the obfuscated Perl section here.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-03-28 16:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found