Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sort a Hash by Values routine?

Posted on 2001-06-19
2
Medium Priority
?
265 Views
Last Modified: 2010-03-05
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 ???

0
Comment
Question by:jgore
2 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 400 total points
ID: 6209123
for( (sort{ $hits{$b} <=> $hits{$a} }keys %hits)[0..19] ){
   print "$_=$hits{$_}\n";
}
0
 

Author Comment

by:jgore
ID: 6209877
Thank you Ozo!
Worked like a charm!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question