in reply to Re^3: s/// not replacing data
in thread s/// not replacing data

####### # 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.

Replies are listed 'Best First'.
Re^5: s/// not replacing data
by Roy Johnson (Monsignor) on Oct 31, 2005 at 17:05 UTC
    Now try:
    while ($sth->fetch) { $username =~ s/\b\Q$badword\b/ **** /gi or print "[$badword] not found in $username\n"; $message =~ s/\b\Q$badword\b/ **** /gi or print "[$badword] not found in $message\n"; }
    The \Q is mostly precautionary, in case $badword might have a regex-special char in it.

    Caution: Contents may have been coded under pressure.