Now I understand that q{} is an operator that returns a string.
q{} (aka single quotes) can be viewed that way, yes. It can also be viewed as a string literal. Is it a constant, the single quote operator or the const operator? It makes no difference.
>perl -MO=Concise,-exec -e"$_ = q{abc};" 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <$> const[PV "abc"] s 4 <#> gvsv[*_] s 5 <2> sassign vKS/2 6 <@> leave[1 ref] vKP/REFC -e syntax OK
Jesus Christ, all these $ variables--I didn't even know there was such a thing.
I made a point of mentioning it in my earlier post.
But the docs say: [...] any variable settings or subroutine and format definitions remain afterwards.
Which of those do you think my $y is?
eval EXPR acts like EXPR is evaluated inside a block [...] Therefore my variables do not survive the end of the block.
Yes. Lexicals created in the file scope of the program passed to eval EXPR cease to exist at the end of the scope.
and the block is nested inside the main program.
Specifically, nested where the eval is located ("executed in the lexical context of the current Perl program"). That means the evaluated code can see the surrounding variables.
I should have said: And when "$temp" is eval()'ed wouldn't the qq{} operator around $temp return a string with the $variables interpolated? Or, is it that the qq{} operator only does one pass of interpolation over "$temp" when "$temp" is eval()'ed.
I'm confused. The example (my $temp = 'xxx$1'; my $repl = eval q{"$temp"};) didn't have a qq{}. I thought you were referring to the double quotes when you said qq{}, but now you're talking about a qq{} in addition to the quotes.
In reply to Re^2: eval problem
by ikegami
in thread eval problem
by 7stud
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |