in reply to Index isn't progressing in C-style for loop
the counter ($lineIndex) in the for loop (c-style) I am using is not progressing from 0. I don't reset it anywhere, and I believe its format is correct within the for loop
The $lineIndex counter is in the inner-loop; are you sure it's not just hitting the conditional and catching the last statement that aborts the loop? This would cause the counter in the inner loop to be 0 the next time it's processed at the next iteration of the outer-loop. Nothing I can see in the provided code should be changing (such as decrementing) the $lineIndex counter.
Perhaps also try printing out the value of your inner loop counter right before calling next to verify it's still set the same as at the loop entry as well, to verify it's the same as when you started as you expect.
Another hint for you, you probably don't want both index() and the regex match against m/$currGB/ since that'll treat the contents of $currGB as a regular expression. Stick with either index(), or look into escaping metacharacters using the quotemeta built-in.
An even more nit-picky style suggestion for you would be to reduce indent level by putting the loop continuation first by reversing the conditional. This is mostly pure style/design preference, but code that needlessly adds to indent level frequently gets harder to maintain in the long-term. Consider:
if ( index($lineinfile, $currGB) == -1 ) { print "Debugging: continuing the loop\n"; next; } # Do your matching workload here.
Update: Sans debugging, you can even use the single line:
next unless ( index($lineinfile, $currGB) != -1 );
|
---|