in reply to Re: hashes sorted by value, but displaying both keys and values
in thread hashes sorted by value, but displaying both keys and values

Hi thanks for that, but I also need to sort alphabetically if the same number is associated with a number of people, such as ->
Steve 1000
John 977
Alice 555
Mike 555
Zoe 555

I'm currently getting something like ->
Steve 1000
John 977
Mike 555
Alice 555
Zoe 555
  • Comment on Re: Re: hashes sorted by value, but displaying both keys and values

Replies are listed 'Best First'.
Re: Re: Re: hashes sorted by value, but displaying both keys and values
by chromatic (Archbishop) on Dec 31, 2003 at 22:50 UTC

    No problem, just throw an extra comparison in the sort block as documented in perldoc -f sort:

    sort { $values{$a} <=> $values{$b} || $a cmp $b } keys %values