in reply to small steps toward Perl literacy, temp vars and parentheses
I'd code that as
use List::Util qw[ min ]; %h = map{ $_, $h{ $_ } } min keys %h;
Which I think clarifies things a lot as well as saving a little runtime.
I also favour breaking chains over several lines as I think it makes it easier to pick out what is going on.
If I needed to keep the lowest 2 or more elements then
%h = map{ $_, $h{ $_ } } ( sort{ $a <=> $b } keys %h )[ 0 .. 2 ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: small steps toward Perl literacy, temp vars and parentheses
by BlaisePascal (Monk) on Jun 17, 2004 at 00:03 UTC | |
by BrowserUk (Patriarch) on Jun 17, 2004 at 00:40 UTC |