in reply to Re^2: Splitting Apache Log Files
in thread Splitting Apache Log Files
qr// is a regular expression quote, and as such does, in a sense, compile regular expressions. Unfortunately, you're using the regular expression as a hash key, at which point it's turned back into a string. As you process the Apache log file, $rule is just a string. When you use it as a regular expression, it has to be compiled again - each time through the loop.
If I were writing your code, I would store the regular expression rules/filehandles in an array. Here's a sketch of what it might look like:
my @rules; # not %rules. ... # Process input file of processing rules while(<INFILE>) { ... push @rules, { regex => qr/$string/, file_handle => $fh }; } ... # Read Apache log file and print to various other files while (my $line = <STDIN>) { for my $rule_ref (@rules){ my $regex = $rule_ref->{regex}; my $fh = $rule_ref->{file_handle}; if ($line =~ $regex) { print $fh $line; } } }
Hope this helps.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Splitting Apache Log Files
by cmm7825 (Novice) on Apr 26, 2010 at 20:16 UTC | |
by BrowserUk (Patriarch) on Apr 26, 2010 at 21:02 UTC | |
by cmm7825 (Novice) on Apr 27, 2010 at 05:36 UTC | |
by BrowserUk (Patriarch) on Apr 27, 2010 at 05:57 UTC | |
by Marshall (Canon) on Apr 27, 2010 at 17:51 UTC |
In Section
Seekers of Perl Wisdom