Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

[HELP] Spam checking [PERL]

Name: Anonymous 2009-03-08 5:38

I'M NOT GOOD WITH COMPUTERS

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.

Please help me.

Name: Anonymous 2009-03-09 4:56

wtf is wrong with you, anyone on here should be able to write something this simple in perl without even thinking

i'm at work, on windows, with restricted network access and no perl interprter but i'm going to write it for you

#!/usr/bin/perl

use warnings;
use strict;

sub spamcheck($) {
  my $string = shift;
  open(SPAM, "spam.txt") or die($!);
  while(<SPAM>) {
    return(-1) if($string =~ m/$_/);
  }
  close(SPAM);
  return(1);
}

while(<>) {
  die("SPAM WARNING") unless(spamcheck($_) == 1);
}

print "no spam found...\n";

exit(0);

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List