Glenn Linderman wrote:
So, $lTokens is a reference from a sub, to a variable declared outside
of the sub (specifically, to the $lTokens declared in parse on its
first invocation), thus making gettoken a closure.... and causing that
instance of $lTokens to be preserved as part of the state of the closure.
Thanks for the explanation. As far as I am concerned, then, perl's
closure model is unintuitive and broken. It doesn't work like closures
in any other language I have seen, including Pascal, Smalltalk, Common
Lisp, Scheme, ML, or Haskell. Don't know about Python or Ruby, but I
suspect they don't make this mistake. It should always create a new
closure for gettoken() each time parse() is run. The workaround, as
mentioned, is to write $gettoken = new sub {...}, instead, but that
workaround shouldn't be required. Hopefully this will be fixed in Perl 6.
--
Lyle Kopnicky
Software Project Engineer
Veicon Technology, Inc.
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs