use strict; &f; #"pre=> ", "post=>2" my $v = 1; &f; #pre=>1", "post=>3" exit; sub f { print "pre=>$v\n"; $v += 2; print "post=>$v\n"; } #### #this code proves that scratchpads keep lexicals around, #not mere copies of those lexicals; something like reference #counting of lexicals is occuring with closures - the details #don't really matter - the $v lexical persists in both the f1 #and f2 closures, not a mere "copy" of $v. sub f_maker { my $v = 1; my $f1 = sub { print "f1_pre =>$v\n"; $v++; print "f1_post=>$v\n"; }; my $f2 = sub { print "f2_pre =>$v\n"; $v++; print "f2_post=>$v\n"; }; return ($f1, $f2); } my ($f1, $f2) = &f_maker; &$f1; &$f2; &$f1; __OUTPUT__ f1_pre =>1 f1_post=>2 f2_pre =>2 f2_post=>3 f1_pre =>3 f1_post=>4