in reply to log parsing very slow
This code is untested but it should work. If you didn't care about preserving the order of the entries you could do away with the array all together.use strict; use warnings; use File::Basename; my (@count, %seen); my @mask = qw(/some/path/ some/other/path another/path); open (FH, '<', "access.log") or die "Unable to open 'access.log' for r +eading: $!"; while (<FH>) { chomp; for my $m (@mask) { my $regex = "GET.*" . $m . ".*HTTP/1.1\" 200 [0-9].*"; if (/$regex/) { s/.*GET //; s/ HTTP.*//; my $bn = basename($_); push @count, $bn if ! $seen{$bn}++; } } } print "$_ = $seen{$_}\n" for @count;
Cheers - L~R
Update: Following the suggestion of others to use qr// external to the loop which will increase the performance of this solution even more. If you can combine the regexes using Regexp::Assemble, there will be an additional boost.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: log parsing very slow
by ChemBoy (Priest) on Oct 05, 2005 at 15:27 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |