Next | Advanced Programming Techniques | Slide #34 |
Closures capture lexical variables
sub make_function { my $val = shift; return sub { print "Value is $val.\n"; ++$val }; }
my $f1 = make_function(3); my $f2 = make_function(20);
Code is shared, pads separate
Pad memory allocated and reclaimed at run time as usual
Next | Copyright © 2000 M-J. Dominus |