in reply to s/// not replacing data

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.

Replies are listed 'Best First'.
Re^2: s/// not replacing data
by Anonymous Monk on Oct 31, 2005 at 16:28 UTC
    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.

        If this is the problem, would it not be easier for them to store the badwords into an array and apply it to each line?


        "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

        sulfericacid

      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

        He's using
        my ($id, $badword); $sth->bind_columns(\$id, \$badword);
        to populate $badword.

        Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
        How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
        ####### # connecting to the DB again so we can filter swear words ####### 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 "the badword was: $badword<br>"; } print "message: $message<br>"; push(@keep_after_swear_words, "$username<!!>$message<!!>$date<!! +>$ip"); }
        Does print out the swearword each time through the loop. I added the test print which I used originally. It's getting the data from the bind'd column.
        Hi guys. Sorry.

        I got the swearwords working with using a suggestion to make an array of badwords and then apply the s///.

        That worksgreat now. I don't know how to apply that same fix or idea for the emoticon filtering beacause it's more than one replacement.

        For emotions there is a face (contains something like: *smile*), a location (containing the URL of the image) and a name (something like: smilie). So it's a three-part s///. How could this be done using the array method because this, too, is having the same problem as the swearwords did.

        Thanks!

        ####### # connecting to the DB again so we can filter emoticons ####### my $data = qq(SELECT id, name, location, face FROM emoticons); my $sth = $dbh->prepare($data); $sth->execute() or die $dbh->errstr; my ($id, $name, $location, $face); $sth->bind_columns(\$id, \$name, \$location, \$face); foreach my $line (@keep) { my ($username, $message, $date, $ip) = split(/<!!>/, $line); while ($sth->fetch) { $message =~ s|(?<!\S)\Q$face\E(?!\S)| <img src="$location" alt=" +$name"> |gi; } if ($message =~ m|^/me|i) { $message =~ s|^/me||i; print qq(<b><i><a href="#" TITLE="Message sent on $date by $ip"> +$username</a></i></b> <i>$message</i><br>); } else { print qq(<b><a href="#" TITLE="Message sent on $date by $ip">$us +ername</a>:</b> $message<br>); } }