use strict; use warnings; my $test = test(); $test->() for (1..3); $test->() for (1..3); sub test{ my $var = 1; return sub { print("private state is ", $var++, "\n") }; } __STDOUT__ private state is 1 private state is 2 private state is 3 private state is 4 private state is 5 private state is 6
In reply to Re: Making a variable in a sub retain its value between calls
by sh1tn
in thread Making a variable in a sub retain its value between calls
by crashtest
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |