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
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|