in reply to Re^2: 'my' and 'state' declaration inside a loop
in thread 'my' and 'state' declaration inside a loop

Well, the "traditional" way is put the "my" variable in the scope of the loop.
#!/usr/bin/perl -w use strict; use 5.10.0; ## my $n; for (1..5) { $n++; say $n } ## wrong foreach my $n (1..5) { say $n;} __END__ 1 2 3 4 5
Update:
Maybe my previous example was not the best. But basically if you have something to initialize before a for loop starts iterating, do it in the for loop! "state" is actually a rather rare thing. You could code Perl for a year or two between using it.