farzanj
asked on
Filtering a lines from a list of keywords
I have massive log files from which I want to filter out lines containing phrases out of a list. So, I have put the words in an array and for every line, I have to go through a foreach loop.
Something like
my @phrases = ( 'phrase1', 'phrase2', 'phraseN');
while(<$filehandle>)
{
foreach my $phrase (@phrases)
{
print if (/$phrase/);
}
}
However this is very slow. Any way I could make it fast?
Something like
my @phrases = ( 'phrase1', 'phrase2', 'phraseN');
while(<$filehandle>)
{
foreach my $phrase (@phrases)
{
print if (/$phrase/);
}
}
However this is very slow. Any way I could make it fast?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for all the help.
ASKER
(?-xism:
In front of my phrases -- once in each the phrase in $_ = qr/$_/ for @phrases; method and only once in the second method like
(?-xism:phrase1|phrase2|ph
Please guide.