http://qs321.pair.com?node_id=316435

mcogan1966 has asked for the wisdom of the Perl Monks concerning the following question:

I have the need to compare 2 arrays. If an element in array exists in array 1 and array 2, remove it from array 1. Right now, I'm doing this by a standard nested loop method, but this is taking way to long. What I'm looking for is a speedy and concise method to do the following:
WORDS: for($x=0; $x<@words; $x++) { foreach(@exclude) { if (($words[$x] =~ m/\W) || # remove non-words ((length($words[$x])) < 4) || # ignore words less than +4 characters (($x > 0) && (lc($words[$x]) eq lc($words[$x-1]))) || # + drop duplicates (lc($words[$x]) eq lc($_)) ) { splice (@words, $x, 1); $x--; next WORDS; } } }
I should note that @words is sorted before this loop begins. That doesn't seem to be creating any slowness in the code, as @words tends to be small in comparison.

Right now, it can take 2-3 seconds each time this loop is running. There as GOT to be a better way to do this than what I have. It works, but not well enough. Must be faster.