I think the key point here is that $1, $2, $3 etc are global variables. Referring to a global from within an anonymous sub doesn't make it a closure.
The following code generates a closure since $x is a lexical in the scope enclosing the anonymous sub:
sub make_closure { my $x = 1; my $closure = sub { return $x++; }; return $closure; } my $cls = make_closure(); print &$cls; print &$cls; print &$cls;
In reply to Re: Using $1,$2 etc in closures..
by grantm
in thread Using $1,$2 etc in closures..
by castaway
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |