LanX has asked for the wisdom of the Perl Monks concerning the following question:
according to perlop#s/PATTERN/REPLACEMENT/ a double eval isn't a double eval but the eval of an interpolation
e Evaluate the right side as an expression. ee Evaluate the right side as a string then eval the result.
At least that's how I understand the distinction between "evaluate as an expression" and "evaluate as a string"...
Problem is that I can't see this distinction, ee produces just
eval ( eval 'RHS' )
eval do { RHS } ¹
for me and not
eval "RHS".
Or what is meant here, if "evaluate as a string" isn't supposed to mean "string resp. var interpolation", what else?
some snippets as demonstration
DB<135> $_='x' => "x" DB<136> $a='$b'; $b="B" => "B" DB<137> s/x/$a.$a/r # -> "$a.$a" (interpolation) => "\$b.\$b" DB<138> s/x/$a.$a/re # -> eval '$a.$a' => "\$b\$b" DB<139> s/x/$a.$a/ree # -> eval "\$b\$b" not eval "\$b.\$b" Scalar found where operator expected at (eval 106)[(eval 105)[multi_pe +rl5db.pl:644]:2] line 1, near "$b$b" ...
but
DB<140> s/x/$a.'.'.$a/ree # -> eval "\$b.\$b" => "BB" DB<141> s/x/$a.'.'.$a/re # -> eval '$a.\'.\'.$a' => "\$b.\$b" DB<142> s/x/$a.'.'.$a/r # -> "$a.'.'.$a" => "\$b.'.'.\$b" DB<143> eval "\$b.'.'.\$b" # what perldoc predicts for line 140 => "B.B"
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
¹) updated: the RHS is precompiled, but eval 'RHS' means runtime compilation
|
|---|