OK, in that case, we can kinda swap logic in the if-statement.
my @matches;
foreach $reg (@regex) {
my $i = 0;
while ($i <= $#array) {
if ($array[$i] =~ /$x/) {
# successful, so this was a match! put it somewhere safe
# also remove it from @array, we don't need to check it ag
+ain
push @matches, $array[$i];
splice(@array, $i, 1);
} else {
# this item didn't pass so keep it and try again next rege
+x
$i++;
}
}
}
Take successful matches, put them somewhere, and remove them since we don't need to ever check them again. In this scenario, you would want to put the regex which accepts the highest number of items first in @regex, so that more is removed from @array earlier.
The replies from other monks also are good advice -- combining into one regex is a great idea as well.
blokhead | [reply] [d/l] |
| [reply] |