The stupid question is the question not asked | |
PerlMonks |
evaluation strategy of perlby mayaTheCat (Scribe) |
on Sep 20, 2002 at 14:07 UTC ( [id://199472]=perlquestion: print w/replies, xml ) | Need Help?? |
mayaTheCat has asked for the wisdom of the Perl Monks concerning the following question:
hi monks,
a while ago I tried to code something similar to the following one:
what I expected as the result of this script was
1 however, what I got was
3 so, I concluded that perl uses a "lazy evaluation" strategy, which means that it does not assign the value of a variable until the value is really needed. for example, in my sample code the variable $i has the value 3 at time the three functions are called.
however, knowing the reason cannot solve my problem. is there a way to force perl to assign the value of the variable at the time the function is defined? ---------------------------------
Back to
Seekers of Perl Wisdom
|
|