Ok, I've been playing with this for hours. I'm not a trained programmer, so what I've learned so far is by trial and error. Please bear with me.

I have a guestbook that someone has been spamming recently. I simply want to create a list of words in a txt file that can be assigned to a variable. Then when the user clicks submit, it checks to see if the comments field contains any of the blocked words in the list. If so, it simply posts a message saying BLOCKED!!. If not, it allows the user to post.

Here's the code I've been playing with. Someone please have a look at it and tell me where I'm going wrong. I can get it to work if I specify the exact word in quotes where you see "@blocked" below in the IF statement. I've tried various combinations of quotes, using $ instead of @, using "eq" instead of =~, and God knows what else. It either blocks nothing, or blocks everything, regardless of the value of $comments. Here's my flawed code.

# Check for blocked text open (BLOCK,"/home/cowpensv/public_html/cgi-bin/block.txt")|| die "Can +t Open block.txt"; @blocked = <BLOCK>; close (BLOCK); if ( $FORM{'comments'} =~ @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;}

In reply to Blocking based on words in a list by matts156

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.