in reply to Blocking based on words in a list
This is somewhat simplistic, not to mention inefficient - the grep continues over every word in the list even if the first word matches. A better approach would use a for loop:chomp for @blocked; # don't expect to match newlines if ( grep { $FORM{'comments'} =~ /\b$_\b/ } @blocked) { ... }
The \b markers are to match at a word boundary, so BLOCK will not be matched in THIS SHOULD BE UNBLOCKED, for example.chomp for @blocked; for my $m (@blocked) { if ($FORM{'comments'} =~ /\b$m\b/) { # print your message here. exit; # could also last outside the loop } }
However you may want to re-think your approach. Simplistic blockers like this rarely achieve the desired results, and often produce too high a level of false positives to be truly useful. YMMV, of course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Blocking based on words in a list
by VSarkiss (Monsignor) on Dec 28, 2005 at 02:28 UTC | |
|
Re^2: Blocking based on words in a list
by strat (Canon) on Dec 28, 2005 at 08:35 UTC |