cens has asked for the wisdom of the Perl Monks concerning the following question:
Scenario:
I have a hash where the key is a username and the value is a score(integer). I want to sort the hash by value, which I can do (a la the camel book). But after that, I want to find out if anyone has the same score, and return the keys of the tie socres. The problem is that I can't figure out how to look through the hash and return the key correctly. I am completely stumped.
I think that I would want to use something like:
@keys = sort{$hash{$a} cmp $hash{$b}} keys %hash;
and say
if ($hash{$a} cmp $hash{$b} = true) {return ($hash{$a} , $hash{$b})}
and stuff that stuff the result in the array. However, I can't get it to work. Any advice would be greatly appreciated, thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: Comparing values in a hash
by merlyn (Sage) on Sep 05, 2002 at 23:11 UTC | |
by VSarkiss (Monsignor) on Sep 06, 2002 at 00:21 UTC | |
by merlyn (Sage) on Sep 06, 2002 at 00:28 UTC | |
by cens (Novice) on Sep 06, 2002 at 00:07 UTC |