Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Blocking based on words in a list

by esskar (Deacon)
on Dec 28, 2005 at 00:43 UTC ( #519468=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://519468]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-12-04 17:35 GMT
Find Nodes?
    Voting Booth?

    No recent polls found