in reply to Re: How to evaluate a variable in a text string
in thread How to evaluate a variable in a text string

Thanks for your reply
My mistake in typing up the code snippet
It is actually -

$string = eval { $_ };
print "<$string>\n";

  • Comment on Re^2: How to evaluate a variable in a text string

Replies are listed 'Best First'.
Re^3: How to evaluate a variable in a text string
by merlyn (Sage) on Mar 28, 2005 at 21:00 UTC
Re^3: How to evaluate a variable in a text string
by tlm (Prior) on Mar 28, 2005 at 22:48 UTC

    It looks like you are confusing the "string form" of eval with the "block form". Try perldoc -f eval to get the full story, and then merlyn's comment may be clearer. To do what you want to do, you need something like

    $string = eval qq("$_");
    where $_ contains your 'test_string_$val'. But as Roy already pointed out, this may not be a very wise thing to do in the first place.

    the lowliest monk