I cannot find the resources for this. I want to escape double quotes with perl and i am new to this language.
Here's what I have:
$comment =~ s/\"/\\\"/g;
It doesn't seem to be working. What is a proper solution?
I cannot find the resources for this. I want to escape double quotes with perl and i am new to this language.
Here's what I have:
$comment =~ s/\"/\\\"/g;
It doesn't seem to be working. What is a proper solution?
One way to insert things that would need escaping, and without counting backslashes
$comment =~ s/"/q(\")/eg;
With /e
modifier the replacement side is evaluated as code, and the result used as replacement. See it in perlop and, say, this post. Here this is used to form a string literal with \
, by q()
.
Note though that in this simple case s/"/\"/
works fine. There is probably more going on in your code, or your quotes come already escaped in which case extra \
affect what you see later.