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. | [reply] |
|
|
That's not what you're doing. You run thru your list of swear words only once, applying it to the first line in @keep. If you intend to apply every substitution to every chat line, you need to either re-fetch the data, or, if there's not that many of them, keep them in memory.
| [reply] [d/l] |
|
|
| [reply] |
|
|
|
|
|
|
| [reply] [d/l] [select] |
|
|
my ($id, $badword);
$sth->bind_columns(\$id, \$badword);
to populate $badword.
| [reply] [d/l] |
|
|
|
|
| [reply] [d/l] [select] |
|
|
|
|
#######
# 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. | [reply] [d/l] |
|
|
|
|
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>);
}
}
| [reply] [d/l] |
|
|