in reply to Interpolating variables in a string
You could try doing a here-script type of thing:
(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 $token = "__UNIQUE_TOKEN__"; $token .= "_" while $str =~ /$token/; chomp (my $new_str = eval qq(<<"$token"\n$str\n$token));
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.
Opinions my own; statements of fact may be in error.
|
---|
In Section
Seekers of Perl Wisdom