in reply to Re: grep troublein thread grep trouble
Are those patterns simple words? If yes you could consider constructing an or-regex:
DB<100> @patterns=qw#one two three# DB<101> $str="one two" DB<102> $re=join "|",@patterns DB<103> print $str =~ m/($re)/g onetwo [download]
UPDATE:
just noticed there are still subtle differences:
DB<106> $str="two one two" DB<107> print $str =~ m/($re)/g twoonetwo DB<108> print grep {$str=~/$_/} @patterns onetwo [download]
Cheers Rolf
DB<120> print scalar grep {"a"=~/$_/} ("a","",undef) 3 [download]