At 03:09 PM 2/8/2006, Glenn Linderman wrote:
Now that I understand the situation, I can offer the following as a way to safely do what I was trying to do in the first place - by creating an anonymous function and assigning it to a variable named $gettoken, then calling it with the syntax &$gettoken(). This has the effect of forcing the closure (i.e. the anonymous function) to be re-built each time that parse() is called instead of just the first time. (Actually, this was suggested to me by Steve Hurst, though at that time I still didn't understand why this was any different than my original code).

Yes, I guess that will work. I'm not sure that the performance would be as good as passing passing the $list to the gettoken function, though. So it depends on whether your goal is to emulate Pascal, or to have good performance. I haven't done the performance study, but the thought of "rebuilding the closure" each time sounds expensive :)

Good point. I think I'll just always pass in the parameters.

New rule to self: When putting one function inside another, pass all required data in - don't rely on the inside function being able to access data in the enclosing function (unless, of course, that's really the behaviour you want, i.e. for the data to remain the same over multiple calls to the outside function). Thanks.

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to