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

Re: Double interpolation of captured substrings

by ihb (Deacon)
on Nov 17, 2004 at 10:21 UTC ( #408356=note: print w/ replies, xml ) Need Help??


in reply to Double interpolation of captured substrings

I would recommend using another way than interpolation to do what you want, but it can still be a fun exercise.

If you don't want to exercise and really need the functionality, look at String::Interpolate.

To show how to do what you tried to do, for educational purposes:

# Use something more sophisticated which escapes properly. sub quote { qq!"$_[0]"! } my ($x, $y, $z) = qw/ X Y Z /; my $str = 'Foo $x bar $y baz $z'; print $str; # Foo $x bar $y baz $z print quote($str); # "Foo $x bar $y baz $z" print eval quote(str); # Foo X bar Y baz Z
First generate a string that is double-quoted. This string then becomes what you would use in Perl if you had a change to type it yourself. Since it now is Perl code, use eval to evaluate it i.e. interpolate the variables.

ihb

See perltoc if you don't know which perldoc to read!
Read argumentation in its context!


Comment on Re: Double interpolation of captured substrings
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-11-28 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (196 votes), past polls