But for a case like this, a simple, direct use of the information in perlre, and the description of "qr" in perlop, would do just as well. You want to make sure that you don't get "false-alarm" matches, like having a match on a target word like "part" when the text file contains "compartment". So you want to enclose your list of words to match in parens, surrounded by word-boundaries, like this:
Of course, if a target word like "work" is supposed to match on tokens like "works" and/or "worked", you should just make sure your list includes all the appropriate forms for each word.my @target_words = qw/list of words/; # or read from a file, or whate +ver my $joined_targets = join "|", @target_words; my $match_regex = qr/\b($joined_targets)\b/; for my $file ( @file_list ) { open( F, "<", $file ); while (<F>) { if ( /$match_regex/ ) { my $mathed_word = $1; store_to_db( $file, $matched_word ); last; } } close F; }
In reply to Re: Perl regex question
by graff
in thread Perl regex question
by anlamarama
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |