if(open(my $SPAM, '<', BOARD_SPAM))
{ flock($SPAM, LOCK_SH);
for(<$SPAM>)
{ Abort('Comment contains blacklisted item') if $comment =~ /$_/gix; }
close($SPAM); }
$ cat spam.txt
test.1
test;2
$ perl test.pl
Comment contains blacklisted item at test.pl line 5, <$SPAM> line 2.
$
Name:
Anonymous2010-05-04 9:04
I tried this on my web server, but the filter still doesn't trigger... Do you think this has something to do with the server itself rather than the code?
Because looking at your code, it doesn't actually do anything different than the one I posted, other than the fact that it doesn't use Tie::File
Also, instead of posting on random forums about this, you should have tried to debug the problem yourself. Simple print "[$1] [$comment]\n" would have shown you exactly what's wrong with what you're doing.
And before some smart asses start accusing perl of being too unpredictable, C's fgets behaves the same way -- does not append a newline to its output if last line of file doesn't have a newline after it.
I figure it out. Apparently, you cannot use spaces in the spam.txt file. Instead of "blacklisted item" you have to use "blacklisted\sitem"
I don't understand why it works this way, but it does!
Name:
Anonymous2010-05-04 11:15
>>16
Also, even though . is a special character in regex. It still filtered out test.1
Which makes things even weirder. Space is not acceptable but . is?
Name:
Anonymous2010-05-04 11:39
>>16
Each line in the spam file is treated as an actual regex. You should begin the regex with \Q (optionally ending in \E), to `quote' the search string (make special characters literal versions of themselves).