> $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.
Lexical variables (such as my $i), are, um, lexically scoped.

When the eval tries to compile the code and sees a $i, it scans out through the lexical scopes looking for a matching $i declaration. This scanning starts at the physical location of the eval itself within the text. ie it looks for my $i in the text of the eval string (somewhere before the $i), then in the text of the anon sub (somewhere before the eval), then in the text of the makeLazy sub (somewhere before the anon sub definition), then in the main body of the file itself (somewhere before the makeLazy definition).

Since it doesn't find a lexical $i delaration in any of those scopes, it assumes you meant the package variable $i, which then gives an error under strictures.

Dave.


In reply to Re^3: Not-so-lazy evaluation? by dave_the_m
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.