Link to home
Start Free TrialLog in
Avatar of BSwabby
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
ASKER CERTIFIED SOLUTION
Avatar of helver
helver

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BSwabby
BSwabby

ASKER

Hi Helver-

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...)
Avatar of ozo
foreach( @sorted_keys_list ){
  print "@{$players{$_}}{'name','score'}\n";
}
Avatar of BSwabby

ASKER

Thanks to you both.