Do you know where your variables are? | |
PerlMonks |
Counting the number of times several strings appearby cspctec (Sexton) |
on Nov 13, 2012 at 16:53 UTC ( [id://1003664]=perlquestion: print w/replies, xml ) | Need Help?? |
cspctec has asked for the wisdom of the Perl Monks concerning the following question: Hello, I have an array that I have dumped a file into. The file contains several hundred different sentences. The array contains, for example: User logged in successfully at 10:35:33 User logged in successfully at 10:35:34 User logged in successfully at 10:35:35 Error: Login failure! User logged in successfully at 10:35:37 Error: Login failure! Error: System failure at 01:23:22 Error: System failure at 01:23:40 User logged in successfully at 10:35:39 Error: System failure at 01:23:41 So... what I've been trying to do is create a perl script to tell me how many times each error occurred. I would need the output to look like: User logged in successfully at 10:35:33 The above event occurred 4 additional times Error: Login failure! The above event occurred 1 additional times Error: System failure at 01:23:22 The above event occurred 2 additional times I have been trying to figure out a way to make the script count each event individually, but the for loops I have been using are only counting the first few matches. Can someone come up with an algorithm that can count these and output the results like I have listed? Thanks for any help you can provide!
Back to
Seekers of Perl Wisdom
|
|