#!/usr/bin/perl sub make_counter_pair { my $start = shift; warn "lexical variable ".\$start." created"; return ( sub { warn "accessing ".\$start; $start++ }, sub { warn "accessing ".\$start; $start++ } ) } my ($c1, $c2) = make_counter_pair(10); my ($c3, $c4) = make_counter_pair(3); print $c1->() . "\n"; print $c2->() . "\n"; print $c1->() . "\n"; print $c2->() . "\n"; print $c3->() . "\n"; print $c4->() . "\n"; print $c3->() . "\n"; print $c4->() . "\n"; #### lexical variable SCALAR(0x604ff0) created at ./837669.pl line 5. lexical variable SCALAR(0x6323f0) created at ./837669.pl line 5. accessing SCALAR(0x604ff0) at ./837669.pl line 8. 10 accessing SCALAR(0x604ff0) at ./837669.pl line 12. 11 accessing SCALAR(0x604ff0) at ./837669.pl line 8. 12 accessing SCALAR(0x604ff0) at ./837669.pl line 12. 13 accessing SCALAR(0x6323f0) at ./837669.pl line 8. 3 accessing SCALAR(0x6323f0) at ./837669.pl line 12. 4 accessing SCALAR(0x6323f0) at ./837669.pl line 8. 5 accessing SCALAR(0x6323f0) at ./837669.pl line 12. 6