in reply to Parsing a log file
I think what you're looking for is to use a hash to store
the values, and a regexp or two to parse the values:
See perlre for details on regular expressions and perldata for information about hashes.use strict; my %count = (); # Read the stuff from STDIN while (<STDIN>) { if (/GET .*(\.[^\s]+) ([0-9]{3})/) { my ($ftype, $reason) = ($1, $2); $count{"$ftype-$reason"}++; } } # Now print the stuff out foreach (keys(%count)) { if (/^(.*)-(.*)$/) { print "Filetype $1, reason $2 has a count of $count{$_}\n"; } }
There is also an evil hacky way of doing this, which is much faster, but requires you to know which filetypes and reason codes you are looking for.
This works because s/// returns the number of items replaced, and is surprisingly fast at doing this on large files...use strict; { local $/ = undef; # Slurp mode my $file = <STDIN>; my $html = $file=~s/\.html 200//g; print "Count of HTML 200 is $html\n"; }
Andrew.
In Section
Seekers of Perl Wisdom