Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^10: Interpolate into replacement with s//?

by philkime (Beadle)
on Nov 24, 2011 at 07:58 UTC ( [id://939817]=note: print w/replies, xml ) Need Help??


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

You mean like this? This doesn't seem to work either:
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;
I know your solution works when you directly give the replacement inline but not if the replacement itself is in a variable. Perhaps you could comment on how to do this in the above code?

Replies are listed 'Best First'.
Re^11: Interpolate into replacement with s//?
by ikegami (Patriarch) on Nov 24, 2011 at 08:01 UTC
    Check what $replace contains...
Re^11: Interpolate into replacement with s//?
by Anonymous Monk on Nov 24, 2011 at 08:06 UTC
    Tip for you
    $string =~ s/$search/ warn "Lets see what we're evaling\n$replace\n\n\n"; eval $replace; /ge;
      Ah. I appear to have been rather stupid, trying to interpolate into single quotes, thanks for the help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://939817]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-16 12:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found