in reply to Re: Extracting and counting string occurences
in thread Extracting and counting string occurences

This will work fine if the input data can be completely relied on to be in exactly the form you expect.

Two things can take a chunk out of your posterior: (a) the data is variable (in any way) -- anything generated by humans is suspect (of course), anything generated by systems written by humans may not be perfect (let's face it); (b) you didn't fully understand the problem. More insidious yet, nobody may notice that the output of this program is incorrect until something REALLY BAD happens.

So, I'd do something like:

if (/^LOGGING: \S+?-(\S+) \S+: (\S+) [^:]*: (\S+)$/) { my ($month, $what, $user) = ($1, $2, $3) ; if ($what eq 'STARTING') { $flushes{$month}{$user}++ ; $flushes{$month}{TOTAL}++ ; } ; } else { # Any error reporting you like, eg: chomp ; print STDERR "Line $.: '$_' ??\n" ; } ;
This is not a lot of extra code. Of course, you could do much more validation of the input and/or be less strict about some things (eg white-space and case)

Who knows, you might be relieved when you discover the file contains:

.... LOGGING: 31-Mar-2008 23:59:10: ENDING ON A HIGH: countryjoe LOGGING: 1-Apr-2008 00:01:22: STARTING FLUSH: gotcha ....
before the auditors.