push(@arrCompletedChains, $strChain);
As it says in perlsyn:
If any part of LIST is an array, "foreach" will get very confused if you add or remove elements within the loop body, for example with "splice". So don't do that.
UNTESTED, but you could see if this is faster:
use List::Util 'first'; # sort largest first my @sorted = sort { length $b <=> length $a } @arrWorkingCompletedChai +ns; my %to_delete; # remove shortest first while ( my $next = pop @sorted ) { if ( first { index( $_, $next ) >= 0 } @sorted ) { ++$to_delete{ $next }; } | @arrWorkingCompletedChains = grep !$to_delete{ $_ }, @arrWorkingComple +tedChains;
In reply to Re: Best method to eliminate substrings from array
by jwkrahn
in thread Best method to eliminate substrings from array
by catemp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |