Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by philkime (Beadle)
on Nov 23, 2011 at 13:29 UTC ( #939657=note: print w/replies, xml ) Need Help??


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

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 ...
  • Comment on Re^8: Interpolate into replacement with s//?

Replies are listed 'Best First'.
Re^9: Interpolate into replacement with s//?
by ikegami (Pope) on Nov 23, 2011 at 17:26 UTC
    I wouldn't. But what do you mean, it's not obvious? To concatenate quotes to a string, use the concatenation operator (.)!
      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?
        Check what $replace contains...
        Tip for you
        $string =~ s/$search/ warn "Lets see what we're evaling\n$replace\n\n\n"; eval $replace; /ge;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://939657]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2018-08-14 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:









    Results (150 votes). Check out past polls.

    Notices?