good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Smaller. Faster. Alternately one could just do my @sortedkeys = sort { $queryterms{$b} <=> $queryterm{$a} || $a cmp $b } keys %queryterms; and then use @queryterm{@sortkeys} instead of @array1 and @sortedkeys (better named, IMO) instead of @array1. update: added key comparing to sort, like the original had. (update: I would note that if you can't use perl's built-in sort, you probably should use a better algorithm. Yours takes O(N**2) comparisions where as perl's sort algorithm (and most of the good sorting algortihms) average O(N log N) comparisions. ) (I forewarn that I have not tested the code here.) In reply to Re: sort a hash array
by wog
|
|