|
|
| Syntactic Confectionery Delight | |
| PerlMonks |
Sorting values of multi-dimensional hashes while retaining key valuesby Daddio (Chaplain) |
| on Jun 25, 2001 at 02:19 UTC ( [id://91167]=perlquestion: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.Daddio has asked for the wisdom of the Perl Monks concerning the following question: Hello, fellow monks. It has been a while since I have actually asked a question since I have found answers to just about everything I have needed in the Super Search. However, this past week I ran into a situation at work where I ended up parsing some logfiles (in a company-only format) to find the "Top 25" hits for either alerts, errors, or warnings for Web applications. Parsing the data was not a real issue, thanks to Perl, but I ended up with a datastructure that looked like this (in pseudo-code): $hash{APP}{SEVERITY}{ERRORCODE} = $count_of_errors;Now, I do pretty well with hashes, and have found a good bit of information in the Super Search looking for things like "sort values multidimensional hash"; in fact that gives me more than a couple of pages worth of hits. I was looking through another listing of hits tonight, hoping to find something pertinent, and stumbled on merlyn's "Inverting a hash to get all keys for this value". This started to help me see one way to do what I was trying to do: invert my hash in order to do the compare. Below, I have posted some basic test code illustrating a method that does seem to work. My questions to you, fellow monks, are:
Output:
This is just sample data and output, and only shows the Top 5, but if I can make this work (better), I can rearrange the output as necessary. And yes, I do use strict and -w. Thanks for the help! D a d d i o
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||