first commit
This commit is contained in:
18
perl/Examples/Chap3/closure-example
Normal file
18
perl/Examples/Chap3/closure-example
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
###
|
||||
### closure-example
|
||||
###
|
||||
|
||||
## Chapter 3 section 5.2
|
||||
|
||||
sub make_counter {
|
||||
my $n = shift;
|
||||
return sub { print "n is ", $n++ };
|
||||
}
|
||||
|
||||
my $x = make_counter(7);
|
||||
my $y = make_counter(20);
|
||||
$x->(); $x->(); $x->();
|
||||
$y->(); $y->(); $y->();
|
||||
$x->();
|
||||
Reference in New Issue
Block a user