in reply to Re: Re: Re: Closures and callbacks...
in thread Closures and callbacks...

Why is read_row a closure?
Because it is saving lexical state by referring to a lexical variable that is above the immediate lexical state. So if you call main::read_row from another package that isn't in the same lexical scope as read_row, it will still work even though @indexes is no longer in scope. This is because the lexical variable @indexes was saved by read_row, ergo, it is a closure. I hope that makes as much sense as I think it does. Hopefully (time forbidding) I'll write up a closure tutorial so I can merlyn any future closure questions ;)
Doesn't read_row just return a list of values, instead of code?
Returning an anonymous sub does not define a function as a closure, see the above explanation for why read_row qualifies as a closure.
HTH

_________
broquaint

  • Comment on Re: Re: Re: Re: Closures and callbacks...