in reply to Re^6: Unable to declare local variable with "use strict".
in thread Unable to declare local variable with "use strict".
Generally, when people speak of a 'closure' in Perl, people mean a specific kind of subroutine, not a block, as your comment seems to indicate.
I wouldn't say it's generally not the block. I would say it's never the block. Besides that, I agree. The subs are closures, not the scope in which the variables reside.
Closures are typically unnamed subroutines
So?
The code featured functions that captures a variable beyond it's normal scope. They are very much closures.
It's really not that atypical either. It happens whenever you have module-level ("global") lexicals. The lexicals would normally fall out of scope when the module finished executing (i.e. before require returns), but they survive thanks to the methods that capture them.
The only difference between named and unnamed subs is when the capture occurs. Named subs are instantiated at compile-time, so they capture at compile-time. Unnamed subs are instantiated at run-time, so they capture at run-time.
|
|---|