in reply to Quasi-sorting a hash by value
Then, if you just want the largest one, that's in the 0th element of @sorted:my %hash = ( BlueTeam => 8, RedTeam => 2, GreenTeam => 4 ); my @sorted = sort { $hash{$b} <=> $hash{$a} } keys %hash; for my $team (@sorted) { print $team, " => ", $hash{$team}, "\n"; }
Is that what you wanted?printf "Largest is team %s: %d\n", $sorted[0], $hash{ $sorted[0] };
|
|---|