in reply to Escape $ inside quotes only

Here's an alternative, whether it's an improvement is your call:)

$str =~ s[("[^"]*?(?<!\\)")] { (my $temp = $1) =~ s[(?<!\\)\$][\Q\$]g; $temp; }mge;

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

Replies are listed 'Best First'.
Re: Re: Escape $ inside quotes only
by eyepopslikeamosquito (Archbishop) on May 07, 2003 at 04:57 UTC

    This fails for me with multiple escaped " inside string. For example:

    my $str = <<'EOS'; "\"$x\"" EOS $str =~ s[("[^"]*?(?<!\\)")] { (my $temp = $1) =~ s[(?<!\\)\$][\Q\$]g; $temp; }mge; print $str;

    does not escape the $.