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.
_________
broquaint
In reply to Re: Re: Re: Re: Closures and callbacks...
by broquaint
in thread Closures and callbacks...
by rdfield
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |