i use below try to search from "search.txt " and find any string which match the regex expression i listed from file "keywords.t xt", however, it fail. if i put keywords like
keyword1
keyword2
then it will works and display line number and keyword, but if use regex expression instead, it won't works. please help.
actually i want to run the perl script and do a counting for number of matches for each regex expression but even the simple one i tried above not works.
thanks.
keyword1
keyword2
then it will works and display line number and keyword, but if use regex expression instead, it won't works. please help.
actually i want to run the perl script and do a counting for number of matches for each regex expression but even the simple one i tried above not works.
thanks.
Code:
open my $keywords, '<', 'c:\perl\csv\keywords.txt' or die "Can't open keywords: $!";
open my $search_file, '<', 'c:\perl\csv\search.txt' or die "Can't open search file: $!";
my $keyword_or = join '|', map {chomp;qr/\Q$_\E/} <$keywords>;
#my $regex = qr|\b($keyword_or)\b|;
#my $regex = qr/$keyword_or/;
my $regex = qr|($keyword_or)|;
while (<$search_file>)
{
while (/$regex/g)
{
print "$.: $1\n";
}
}
Comment