カウンター カウンターを返す関数make_counter() sub make_counter { my $counter = shift; sub { $counter++ }; } 実行例 $c1 = make_counter(10); $c2 = make_counter(20); print "c1: ", $c1->(), "\n"; print "c2: ", $c2->(), "\n"; print "c2: ", $c2->(), "\n"; print "c1: ", $c1->(), "\n"; 実行結果 c1: 10 c2: 20 c2: 21 c1: 11