BSwabby
asked on
Easy Sorting Question
I'm sure this question has been asked and answered hundreds of times on EE, but in the time it would take to find it I can just ask it again...
I have a hash called players. The keys are simply integers numbering the players. The values are as follows:
$players{key}{name}
$players{key}{score}
$players{key}{losses}
.
.
.
etc.
I need to output a list to the user with all players and their corresponding values listed, but I want the list sorted by score. I've written a bunch of simple sorts that are close, but they are not getting the job done.
Thanks,
Brian
I have a hash called players. The keys are simply integers numbering the players. The values are as follows:
$players{key}{name}
$players{key}{score}
$players{key}{losses}
.
.
.
etc.
I need to output a list to the user with all players and their corresponding values listed, but I want the list sorted by score. I've written a bunch of simple sorts that are close, but they are not getting the job done.
Thanks,
Brian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
foreach( @sorted_keys_list ){
print "@{$players{$_}}{'name','s core'}\n";
}
print "@{$players{$_}}{'name','s
}
ASKER
Thanks to you both.
ASKER
Thanks for the code; it's exactly right. The sick thing is I had the EXACT same sort code, but am having trouble printing the players and scores out of sorted_keys_list. Any ideas on this one? (I know it's rude to ask you a second question, but you're getting the points either way-- don't worry...)