in reply to Re^2: Please help me understand string eval better
in thread Please help me understand string eval better

That's why I'm wondering if between option 1 and option 3 there is a difference.

use strict; use warnings; my $foo='$ans='; my $var=\$foo; my $transf='5;' ; my $r5='$ans="hithere";'; my $var5=\$r5; testit("$$var$transf"); testit("${$var}$transf"); testit($$var.$transf); testit('$$var'.$transf); sub testit { my $ans; my $string=shift; $ans='???'; my $eret=eval $string; printf 'String:%-20s',$string; printf ' $ans:%-10s',$ans; printf ' $eret:%-10s',$eret; print "\n"; } # testit
Result
String:$ans=5; $ans:5 $eret:5 String:$ans=5; $ans:5 $eret:5 String:$ans=5; $ans:5 $eret:5 String:$$var5; $ans:??? $eret:$ans="hithere";
Yea i think there is a difference.

And i dont think you would be talking about "run time" if you understood the multiple compile and run times involved. First your script containing the eval is compiled, and then run. At the this "run time", the '$$var' is just a literal, two dollar signs and then 3 letters. when this run time reaches an eval command it then "restarts?" the perl compiler, to compile whatever string is handed to it, this is when the literal '$$var' is considered code. And then there is a run time for that compiled eval string. It runs that compiled code and returns the "last thing".