in reply to Re^7: In place search and replace with a hash
in thread In place search and replace with a hash
I originally wrote "evaled" and changed it to avoid confusion with string eval.
But actually it is first evaled¹ and then of course stringified.
It's a subexpression returning a value, even within interpolation:
DB<119> %h=(1=>42) => (1, 42) DB<120> $a=2 => 2 DB<121> "<<< $h{3-$a} >>>" => "<<< 42 >>>"
so 3-$a is of course executed.
> Thanks for raising some interesting distinctions.
I took your "?" as a question. :)
May sound like nitpicking, but I'm convinced Perl's behavior needs a more axiomatic (mathematical) explanation.
Otherwise people rely far to often on try-and-error coding and consequently cargo cult, believing that the interpolation on the RHS of s/// is just one other magic DWIM mechanism.
Even more important if one tries understanding what s///e and s///ee do.
That's why I once wrote:
s/RegEx/substitutions/: Variable interpolation and when to use /e - modifiers
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
|
|---|