in reply to Re^2: Foreach Loops
in thread Foreach Loops
I am using a flip-flop as a counter. Of the conditions I gave it, the left side is always true and the right is always false, so the expression is always true. It is a property of the operator that it returns a count of the number of consecutive times it has been true. So subtracting one from that gives you the index.
Unless there are redos or nexts, which would throw it off. So I really should have written
Well, actually, I shouldn't have written it at all as a solution to this question. But I like putting little-used operators into the spotlight so that people might think of them when they actually are appropriate.my $index = 0; for my $line (@arr) { next if $index % 4 == 0; print "$index = $line\n"; } continue { $index = (1=~//..1=~/0/); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Foreach Loops
by tbone1 (Monsignor) on Mar 16, 2005 at 13:03 UTC | |
by Roy Johnson (Monsignor) on Mar 16, 2005 at 13:57 UTC | |
Re^4: Foreach Loops
by Anonymous Monk on Mar 16, 2005 at 12:44 UTC |