in reply to Re: (Ovid) Re: Sub Definitions Within Subs: Best Way to Exploit
in thread Sub Definitions Within Subs: Best Way to Exploit
which will print abcabc. The change to the $foo variable in the second call does not affect subroutine bar. It has a 'closed', localised and personal $foo variable, that cannot be changed by outside influences - only by bar itself. Thus the name 'closure'.sub baz { my $foo=shift; sub bar { print $foo; } } baz("abc"); bar; baz("123"); bar;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Definition of a Closure
by perrin (Chancellor) on Oct 11, 2001 at 18:09 UTC | |
by htoug (Deacon) on Oct 12, 2001 at 12:33 UTC |