in reply to Nailing down closures!

Actually, the output is:

Global symbol "$i" requires explicit package name at ./z.pl line 13. Execution of ./z.pl aborted due to compilation errors.
Well, it would be if you would use strict. This would also do a lot to help you understand the closure you're using here. The $i inside the outter braces is a lexical that goes out of scope - while the $i that you have outside the braces is the global $i. You're probably confusing them with being the same variable.

Try some more tests - e.g., move the $i=10 line inside the braces, and suddenly you'll get 13. That's because you're now affecting the same lexical $i that addone is using. Hopefully that will help cement the idea :-)

Note that not all anonymous subs are closures. That's just one really great use of anonymous subs. For example:

use File::Find; find(sub { rmdir $_ || unlink $_ }, @ARGV);
This is an anonymous sub, but it isn't a closure - it isn't "closed" on any lexical variable. (PS - don't run that blindly ;->)