in reply to Re^5: Interpolate into replacement with s//?
in thread Interpolate into replacement with s//?

I can't seem to work out the quoting when the string is from elsewhere:
use 5.014000; use Config::General; my $conf = new Config::General({replace => 'Z\l$1Z'}); my $string = q/ABC/; my $search = qr/^(A)/; say $conf->{config}{replace}; my $replace = q/$conf->{config}{replace}/; $string =~ s/$search/$replace/gee; say $string;
gives:
Z\l$1Z Z\l$1ZBC
I've tried all sorts of combinations of quoting and regexp flags but I can't seem to get it to work when $replace isn't explicitly assigned as in your example.

Replies are listed 'Best First'.
Re^7: Interpolate into replacement with s//?
by ikegami (Patriarch) on Nov 14, 2011 at 19:15 UTC

    Z\l$1Z is not "Z\l$1Z". Please reread what I wrote.

      I see that but how would you quote in my last example where the replacement comes from an external source? It's not so obvious in this case ...
        I wouldn't. But what do you mean, it's not obvious? To concatenate quotes to a string, use the concatenation operator (.)!