1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
use 5.012; use warnings; sub count { my $i = 0; return sub { $i++ }; } my $counter_var = count(); say $counter_var->(); # 0 say $counter_var->(); # 1 say $counter_var->(); # 2 say $counter_var->(); # 3 say $counter_var->(); # 4
You can clone a snippet to your computer for local editing. Learn more.