http://www.perlmonks.org?node_id=741886


in reply to Evaluating $1 construct in literal replacement expression

How can I expand variables in text strings?
  • Comment on Re: Evaluating $1 construct in literal replacement expression

Replies are listed 'Best First'.
Re^2: Evaluating $1 construct in literal replacement expression
by Anonymous Monk on Feb 06, 2009 at 13:04 UTC
    If you mean for example expand "abc $var xyz" so that the string $var is replaced by the value of $var then eval is the only way I know.

    my $var = "123"; my $str = 'abc $var def'; my $temp = eval " \"$str;\" "; print "str2:$temp\n";