slicks1 slicks1 - 1 year ago 76
Perl Question

Escaping double quotes fix

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?

Answer Source

One way, to avoid counting backslashes

$comment =~ s/"/q(\")/eg;

The /e modifier evaluates the replacement part, where you force a literal string 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download