Hacker News new | past | comments | ask | show | jobs | submit login

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.

For more info, see: http://www.perlmonks.org/?node_id=389319

HTH




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: