> $i is not declared when your string is eval()d
That baffles me. At compile time, perl is just having a string. It is at run time, when the execution reaches the $part2->(); statement that the string is evaled inplace and the string is compiled and evaled. At that point in time, $i should be declared (initial post , perl codelisting 2) in my newbie opinion.

Basically that opinion shows faulty but questions still remains. When is $i evaled? Or in what dictionary/environment/whatever-mechanism-is-used?

The value of $i that is printed (in the first perl program) is the value that i was expecting IF it was evaled at the line $part2->(); It looks to me like there is a mismatch between the places where it is defined and where it is executed. I am assuming this to be the same place. If it is at the place of definition of makeLazyFunction, then i expect $i to have the value 1 and not 2. If it is at the place of $part2->(), then i expect $i to have the value 2 and to be defined as well. Are both views erroneous? What is the correct view?

> Why are you not just doing
Because of the same problem i run into with my code (but i didnt knew until now that it was the same problem): if you defer the declaration of $i then you get Global symbol "$i" requires explicit package name at test1.pl line 7. Only with my code it doesnt show because the error is only generated at run-time and is not printed. No printing, no error i was thinking, alas mistakenly.

In reply to Re^2: Not-so-lazy evaluation? by mtroost
in thread Not-so-lazy evaluation? by mtroost

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.