Re: Matching at least $x words out of @words

Aaron Crane <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
Rick Delaney writes:
> The overlapping strings also cause problems for this method:
> 
>     $x <= grep { $string =~ m/$_/ } @words;
> 
> If $string is "foobar" and @words is qw(foo foobar) then this results
> in two words found which I don't think the OP was looking for.

  $x <= grep { $string =~ /\b\Q$_\E\b/ } @words;

-- 
Aaron Crane
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.