Use an index explicitly instead of the easily broken, implicit one you've coded. It's important to iterate in reverse so your index will still make sense after removing data. That you have these two arrays where elements exist in pairs indicates that your data structure is mismatched. This would be better served by having an array of pairs.
foreach my $ix ( reverse 0 .. $#text ) { if ( not length $text[ $ix ] ) { splice @text, $ix, 1; splice @links, $ix, 1; } }
The previous is optimal on very recent perls and less so on anything older. This is a great reason to use a three-arg for loop.
for ( my $ix = $#text; $ix >= 0; -- $ix ) { # same loop contents. }
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
In reply to Re^3: Regexp works with some elements and doesn't with others
by diotalevi
in thread Regexp works with some elements and doesn't with others
by lampros21_7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |