When the anonymous subroutine that is stored in $ref1 is created it increases the reference count for that instance of $n to 2.{ my $n = 10; $ref1 = sub { print( $n++, "\n" ) }; $ref2 = sub { print( $n++, "\n" ) }; }
When the anonymous subroutine that is stored in $ref2 is created it increases the reference count for that instance of $n to 3.
The two anonymous subroutines share the same $n in this case.
In reply to Re^3: Using an "outer" lexical in a sub?
by imp
in thread Using an "outer" lexical in a sub?
by cornballer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |