Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

In somewhat regards to my SOPW yesterday, I am having problems applying a swear filter to some text.

When I test print '$badword' it prints a list like

'badword1' 'badword2' 'badword3' and so on
So I know the retrieved words are correct. I've done plenty of test prints to see what's going on throughout this process. I am thinking it has something to do with the s/// itself beacause it doesn't catch on- anywhere.
# @keep has all the messages in it. # @keep_after_swear_words should be the filtered version of @keep my $data = qq(SELECT id, word FROM swears); my $sth = $dbh->prepare($data); $sth->execute() or die $dbh->errstr; my ($id, $badword); $sth->bind_columns(\$id, \$badword); foreach my $line (reverse @keep) { my ($username, $message, $date, $ip) = split(/<!!>/, $line); #print "user: $username<br> message: $message<br> date: $date +<br> ip: $ip<br><br>"; while ($sth->fetch) { $username =~ s/\b$badword\b/ **** /gi; $message =~ s/\b$badword\b/ **** /gi; } print "message: $message<br>"; push(@keep_after_swear_words, "$username<!!>$message<!!>$date<!! +>$ip"); } #.. print out modified text here
Can anyone possibly see why this swear filter isn't catching words?

Replies are listed 'Best First'.
Re: s/// not replacing data
by Roy Johnson (Monsignor) on Oct 31, 2005 at 16:21 UTC
    What are you $sth->fetching, and why are your substitutions in that loop? If that doesn't yield anything, the calls to s/// aren't going to happen.

    Caution: Contents may have been coded under pressure.
      The fetch is to retrieve the swearwords from the database. It does it because I can print out the swearwords.

      The process is like this:

      1) All the chat info (name, message, ip, time) is retrieved from the DB and placed into an array @keep.
      2) The list of my swear words are fetched and applied to the data above. This is pushed into the new array @keep_after_swear_words.
      3) The emoticon filters then optimizes the swear-filtered data and applies it's last filter
      4) The text is then printed to screen.

        Yes, but how are you assigning the results of $sth->fetch() to $badword? That seems to be missing. Perhaps $badword is never being populated. You can test this by putting a print "$badword\n"; into your while loop.


        Dave

Re: s/// not replacing data
by stonecolddevin (Parson) on Oct 31, 2005 at 21:41 UTC