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

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>); } }

Replies are listed 'Best First'.
Re^5: s/// not replacing data
by Roy Johnson (Monsignor) on Oct 31, 2005 at 17:30 UTC
    You could put your execute and bind statements inside the foreach loop, which would cause the query to be executed for each line in @keep.

    Or you could assemble an array outside the foreach loop something like:

    my @emoticons; push @emoticons, [$id, $name, $location, $face] while $sth->fetch;
    Then inside your foreach, instead of the while/fetch, you'd have something like:
    foreach my $emote_aref (@emoticons) { ($id, $name, $location, $face) = @$emote_aref; ...

    Caution: Contents may have been coded under pressure.