You can also just store a reference to your lexical in a
global to simulate the same thing. Yes, "global" "closures"
are probably harder to notice than global variables, but
the same basic principle applies: keeping a reference to
something around prevents it from being destroyed (until
global destruction, of course).
But none of that changes the fact that you can avoid the
problems with misordered destruction by using only lexical
(including making sure that any references to said lexicals
are also only in lexicals, etc.). That is a very practical
bit of information.
Also, current versions of Perl create a reference loop for
"real" closures and so they would also cause you problems
(as well as leaking memory if you create lots of closures).
-
tye
(but my friends call me "Tye")