sub spamcheck() {
open(SPAM, "<spam.txt") || die 'MISSING';
@raw_data=<SPAM>;
close(SPAM);
for(@raw_data) {
/^(.*)$/;
my $blocked = $1;
die 'SPAM' if $comment =~ $blocked;
}
}
I'm trying to make some sort of spamchecker so when a person submits a comment, it is checked against spam.txt and if it doesn't match any of the lines, then it is allowed to continute.
However this bit of code isn't working for me. For example, I have spam.txt with several lines of test words, the first line is derp and when I submit a comment with the word derp it doesn't stop the comment from being submitted. However, when I submit a comment with derp and then a newline, it errors as it's supposed to. But it only does with with the first line. The other lines in spam.txt don't trigger it at all.
That reminds me, I had a weird problem with the Data::Dumper output of some hash references if I chomped the elements. Maybe I'll post it later.
Name:
Anonymous2009-03-08 21:41
None of these suggestions seem to work. In fact, I've come to realize that the code I originally posted actually works, with the exception of having to have a newline after the blacklisted item in order to trigger the spam filter hours after you guys had already told me. I just really needed time to let it sink in after experimenting with it. Turns out I was doing it wrong in spam.txt by not putting < instead of < and [ instead of [ so the spam filter would not trigger, obviously.
Also, this is weird, I took my script to another server to test it and it works perfectly, no newline issues. I was not expecting that.
Oh right, \ doesn't show up in italics, silly BBCode.
Name:
Anonymous2009-03-09 2:34
This blows, chomp doesn't seem to be doing its thing.
sub spamcheck() {
open(SPAM, "<spam.txt") || die 'spam.txt is missing';
while (<SPAM>) {
/^(.*?)$/;
my ($blocked) = ($1);
chomp($blocked);
die 'Your post was detected as spam' if $comment =~ /$blocked/i;
}
}
What am I doing wrong? Spamcheck still isn't triggered unless the blacklisted item is followed by a new line. CHOOOOOOOOMMMMMMP!!!
>>18
The real question is: Why would anyone want to write in outdated languages like Perl when they could write it much faster and less error-prone in a more modern language?
Next you'll suggest actually doing non-toy projects in LISP. Hahaha.
I amended the code as such: sub spamcheck() {
open(SPAM, "<spam.txt") || die 'spam.txt is missing';
while (<SPAM>) {
/^(.*?)(\r*\n*)$/;
die 'Your post was detected as spam' if $comment =~ /$1/i;
}
}