in reply to YAlQ: Yet Another local() Question.
returns:sub add($); sub ladd($); my $addOne = add(1); my $laddOne = ladd(1); &$addOne(0); &$addOne(1); &$laddOne(0); &$laddOne(1); sub add($) { my $add = $_[ 0 ]; return sub { my $num = $_[ 0 ]; my $sum = $num + $add; print "$num + $add = $sum\n"; }; } sub ladd($) { local $add = $_[ 0 ]; return sub { local $num = $_[ 0 ]; local $sum = $num + $add; print "$num + $add = $sum\n"; }; }
jeff0 + 1 = 1 1 + 1 = 2 0 + = 0 1 + = 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: YAlQ: Yet Another local() Question.
by BlaisePascal (Monk) on Aug 03, 2000 at 18:26 UTC | |
by jlistf (Monk) on Aug 03, 2000 at 18:38 UTC | |
by BlaisePascal (Monk) on Aug 03, 2000 at 18:45 UTC |