> $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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |