Problems? Is your data what you think it is? | |
PerlMonks |
Re: looping through an arrayby reasonablekeith (Deacon) |
on Apr 25, 2006 at 13:00 UTC ( [id://545552]=note: print w/replies, xml ) | Need Help?? |
Well, this is how I'd do it, but it's a bit lazy really. I normally like to self document, and joining the three extracted variables into one string isn't too descriptive. That said it works like this.
There are two stages, firstly going through the data and building a hash, the keys of which are all the unique combination of src_ip, dest_ip, and port. This key's value is incremented each time it's found, and so the value of the hash key forms our count value. Then it's just a case of going through the keys, spliting them apart so we can join them in the correct format, and printing the count value. If you were going to do anything more complicated than this then you should probably store your data in a hash of hash format, rather than my mangled string example, but I had to leave you with something to do :) anyway, here's the code...
--- my name's not Keith, and I'm not reasonable.
In Section
Seekers of Perl Wisdom
|
|