in reply to Re: Anonymous subroutines
in thread Anonymous subroutines
Which is part of the standard language now. :)
> because the inner sub would get bound to one my variable
Basically, it's a 1-to-n problem, because closures are supposed to be created many times.
But named subs are only once assigned globally and bound to a type-glob in the current package (think our ) at compile time (think BEGIN {...} )
Nowthe compiler sees the use of lexical variables from the outer scope, which potentially change with every invocation. (The former are not destroyed) and emits the "won't stay shared" warning.
An anonymous closure sub OTOH would be assigned each time and have a deep-binding to the current outer scope.
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
|---|