http://www.perlmonks.org?node_id=29218

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I would like to replace , with \",\" in a similar way that printing it would mean doing print "\\\",\\\""

Originally posted as a Categorized Question.

  • Comment on How do I surround commas with escaped double-quotes?

Replies are listed 'Best First'.
Re: How do I surround commas with escaped double-quotes?
by Shendal (Hermit) on Aug 23, 2000 at 19:50 UTC
    $_ = ','; s!,!"\\\\\\",\\\\\\""!; print "$_\n";
    This prints:
    "\\\",\\\""
    Is this what you're looking for?
Re: How do I surround commas with escaped double-quotes?
by tye (Sage) on Jan 07, 2001 at 10:36 UTC
    $string= "This, that, and those"; $string =~ s/,/\\",\\"/g; print $string;
    Prints:
    This\",\" that\",\" and those
Re: How do I surround commas with escaped double-quotes?
by Anonymous Monk on Aug 23, 2000 at 19:46 UTC
    sorry, I was not so clear with my question. I would like to replace , with \",\" in a similar way that printing it would mean doing print "\\\",\\\""

    Originally posted as a Categorized Answer.

Re: How do I surround commas with escaped double-quotes?
by georgebailey (Initiate) on Jan 07, 2001 at 04:03 UTC
    Still don't understand your question.

    Perhaps you should rewrite it like this:

    I've got a string that looks like

    give an example

    but I need it to look like this instead

    give an example

    so I can do this with it:

    tell us what you're trying to do

    Originally posted as a Categorized Answer.

Re: How do I surround commas with escaped double-quotes?
by davorg (Chancellor) on Aug 23, 2000 at 19:44 UTC
    s/,/","/g;