Posted By: znouza (- Armored Pilsener -) on 'CZscripts'
Title:     Re: Perl - setrideni hashe posle values.
Date:      Sun Apr 30 20:42:57 2000

> > 
> > Jak se tridi hash podle hodnot?
> 
> hash nema obecne zarucene "poradi", takze chces neco jako
> 
> print "$_ => $hash{$_}n" foreach (sort{$hash{$a} cmp $hash{$b}}keys %hash);
> 
> 
> 
> -- Trifid@Redigy.Cz ---------------------------------------------- ? --

a co tohle?

foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash) {
                       printf "%4d %sn", $hash{$key}, $key;
                   }
;)
popr. man perlfunc, fce sort
# this sorts the %age hash by value instead of key
# using an in-line function
@eldest = sort { $age{$b} <=> $age{$a} } keys %age;


     _  _    /--------                      znouza
   ( o)(o ) /__________
      ||        | |
      ||        |_|           "The game of life is hard to play..."
      **      __|                              3T 

Search the boards