To have a value persist between invocations of a subroutine, you can use a variable that exists outside the scope of the subroutine. There are various ways to do this, one of which is as follows. I added a limit on recursion.
use strict; use warnings; testFunc(); { my $i = 0; sub testFunc { $i++; print "$i\n"; testFunc() if($i <10); } }
In reply to Remembering the value of a variable
by ig
in thread value of returned array, and remember variable in recursive function
by The Elite Noob
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |