Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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 }


Comment on Re: Blocking based on words in a list
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2015-07-04 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls