The lexical scoping rules are precisely what causes this behaviour. The first example defines a nested function which has access to the variables in scope when defined (as you remark).
It's little different than this block defined outside of any function:
{
my $v;
sub b { ... }
}
Whereas an anonymous function is "defined" each time the enclosing scope is evaluated.
It's little different than this block defined outside of any function:
Whereas an anonymous function is "defined" each time the enclosing scope is evaluated.For more info, see: http://www.perlmonks.org/?node_id=389319
HTH