in reply to Re: Foreach Loops
in thread Foreach Loops

You should really put the counter increment in the continue block, though, in case of next or redo. Compare:
my @arr = ('a'..'m'); my $i=0; foreach (@arr) { # stuff goes here next if $i%4 == 0; print "$i: $_\n"; } continue { ++$i } $i = 0; foreach (@arr) { # stuff goes here next if $i%4 == 0; print "$i: $_\n"; ++$i; }

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.