The correct HTML would be produced by using "
my $name = 'John "FOO" Rambo';
$name =~ s/"/"/g;
my $html = "<span title=\"The great and mighty $name\"/>";
print $html ."\n";
For clarify on your original question:
You can use simple regular expression to substitute quotes.
Example:
my $name = 'John "FOO" Rambo';
$name =~ s/"/\\"/g;
my $html = "<span title=\"The great and mighty $name\"/>";
print $html ."\n";
This
$name =~ s/"/\\"/g;
simply says replace all "
with \"
(but since \
is special character is needs to be escaped as \\"
.
the g
means globally
, i.e. all occurences within the string.
(i.e. if you run only $name =~ s/"/\\"/;
then $name
would be John \"FOO" Rambo
, but with g
it is John \"FOO\" Rambo
)
But this won't produce a valid HTML