Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Interpolating variables in a string

by dpuu (Chaplain)
on Oct 13, 2004 at 22:26 UTC ( #399033=note: print w/ replies, xml ) Need Help??


in reply to Interpolating variables in a string

You could try doing a here-script type of thing:

my $token = "__UNIQUE_TOKEN__"; $token .= "_" while $str =~ /$token/; chomp (my $new_str = eval qq(<<"$token"\n$str\n$token));
(I haven't tested that, but it feels like it might work). What I usually do for this type of thing is to not rely on lexical variables in my program, and instead set up a separate hash of legal variables:
my %vars = ( var => "foo" ); $str = 'abc $var def'; (my $new_str = $str) =~ /\$(\w+)/$vars{$1}/g;
--Dave
Opinions my own; statements of fact may be in error.


Comment on Re: Interpolating variables in a string
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2015-07-06 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (73 votes), past polls