in reply to Re: Pattern match array
in thread Pattern match array
You probably want to use word boundary anchors so that you don't get false positives with fprintf when looking for int etc.
I agree. In other words, break the text into words before attempting to match entire words. So all the regex engine is doing is replicating an inner for-loop with an eq test.
while ( <> ) { for my $word ( m{\b(\w+)\b}g ) { if (grep {$word eq $_} @prims) { print qq{Found $word on line $.\n}; } } }
Update: which, of course, vindicates thezip's hash-based solution in the first response to this question.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Pattern match array
by johngg (Canon) on May 08, 2008 at 13:52 UTC | |
by Narveson (Chaplain) on May 09, 2008 at 06:22 UTC | |
by johngg (Canon) on May 09, 2008 at 13:56 UTC |