in reply to Modifying 'next' in foreach loop
Given the way you're processing the file, I think you need to include a state indicator.
There are terser ways of representing this, but I think this is readable. (It is untested, be warned!)my $changed = 0; foreach $line (@lines) { if ($line =~m/^SY /) { if ( $changed == 0 ) { $line =~ s/^SY/CN/) $changed = 1; } else { $line =~ s/^SY/ /; $changed = 0; } } else { $changed = 0; } }
|
|---|