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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Counting the number of times several strings appear
by thundergnat (Deacon) on Nov 13, 2012 at 17:52 UTC | |
by cspctec (Sexton) on Nov 13, 2012 at 18:19 UTC | |
Re: Counting the number of times several strings appear
by Kenosis (Priest) on Nov 13, 2012 at 17:01 UTC | |
by cspctec (Sexton) on Nov 13, 2012 at 17:18 UTC | |
by 2teez (Vicar) on Nov 13, 2012 at 17:29 UTC | |
by cspctec (Sexton) on Nov 13, 2012 at 17:36 UTC | |
Re: Counting the number of times several strings appear
by rpnoble419 (Pilgrim) on Nov 13, 2012 at 17:22 UTC |
Back to
Seekers of Perl Wisdom