in reply to Blocking based on words in a list

i see this construct very often ($scalar =~ @array) but it's totally wrong... you have to check very entry in that blocked-array.
reading all entries into an array can be slow and memory consumming and actually there is not need to use regexp's heer. so i would change the code like this.
if(open (my $filehandle, '<', '/home/cowpensv/public_html/cgi-bin/bloc +k.txt')) { my $comments = $FORM{'comments'}; my $is_blocked = 0; while ($is_blocked == 0 && (my $word = <$filehandle>)) { chomp $word; $is_blocked = 1 if index($comments, $word) > -1; } close $filehandle; if ( $is_blocked ) { print "Content-type: text/html\n\n"; print "<html><head><title>Blocked</title></head>\n"; print "<body><h1>BLOCKED!!</h1>\n"; print "\n</body></html>\n"; exit; } } else { die "Can't open block.txt"; # or any other error-handling # i don't like die in a cgi-env }

Replies are listed 'Best First'.
Re^2: Blocking based on words in a list
by matts156 (Novice) on Dec 28, 2005 at 01:37 UTC
    Hey, you're awesome. That worked just great. One of these days, I'm going to take a class on this stuff.