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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.