Sort a Hash by Values routine?

Sort a Hash by Values routine?

I'm writing a routine that interprets a Log file.
I'm saving the info about browsers in a hash and wish to show the Top-20 Browsers.
Like:    Mozilla/4.77   would be a log entry ,key, for netscape with perhaps the value of '50'.

My dumb problem:
Once I have a hash full of browser names as key, and how many hits for each in values.....what then?  What is an elegant way to find the top-20 ???

jgoreAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ozoConnect With a Mentor Commented:
for( (sort{ $hits{$b} <=> $hits{$a} }keys %hits)[0..19] ){
   print "$_=$hits{$_}\n";
}
0
 
jgoreAuthor Commented:
Thank you Ozo!
Worked like a charm!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.