PDA

View Full Version : Substitute an apostrophe


zenweezil
07-29-2004, 03:54 AM
Normally if I want to change a to b I do this:

$variable =~ s/a/b/g;

But am running into multiple issues when trying to replace an apostrophe and turn it into two apostrophes (' into '') for the obvious reasons of perl's use of single quotes.

Any ideas how I can do this effectively?

I tried escaping the quotes but was unsuccessful for some reason.

Calilo
07-29-2004, 05:11 AM
this works just tested it, maybe you forgot to escpae both the single and double quote.


$variable =~ s/\'/\"/g;


Calilo

zenweezil
07-30-2004, 06:28 AM
I didn't realize perl saw a difference between ’ and ' - but it does.

So this is what I ended up using to go from a "smart" apostrophe to two single apostrophes

$variable =~ s/\’/\'\'/g;

THANKS FOR THE ASSIST!