in reply to Re: problem in sorting has by value
in thread problem in sorting hash by value
If the sort field is just a hash key lookup, its not worthwhile to do the Schwartzian thing (even with the hash dereference). You have to build an array reference, and then dereference it, so its only worth it for more expensive operations. Just do a straight sort:<code> sort { $thishash->{$b} <=> $thishash->{$a} } keys %thishash;foreach my $key (map { $_->[0] } sort { $b->[1] <=> $a->[1] } map { [ $_, $thishash->{$_} ] } keys %$thishash;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: problem in sorting has by value
by dragonchild (Archbishop) on Dec 11, 2001 at 22:00 UTC |