This little excerpt should be a fair proof that the basic idea works:
my $message = 'one :-* smiley';
my ($face, $location, $name) = (':-*', 'here', 'smoochie');
$message =~ s/\Q$face\E/ <img src="$location" alt="$name"> /gi;
print $message, "\n";
Now what you need to do is figure out how your situation differs. That means putting in print statements so you can see what's really going on every step of the way, and then examining the output for what wasn't what you expected it to be. Start by replacing your if-face-block with something like
if ($face)
{
if ($message =~ s/\Q$face\E/ <img src="$location" alt="$name">
+ /gi)
{
print "Substituted for [$face] in [$message]\n";
}
else
{
print "[$face] was not found in [$message]\n";
}
}
else
{
print "$face was not true!\n";
}
That way, you get a definite indication of what path things took and what your variables were. Something will probably jump out at you.
Caution: Contents may have been coded under pressure.
|