in reply to Re: How to splice out multiple entries from an array
in thread How to splice out multiple entries from an array

Actually, the above algorithm is not particularly suitable for the OP's needs. Its relevent as a indicator on what to do but it doesnt solve his problem in the most efficient way.

If you read the code, and assume that @arr1 is large, without many duplicates, and that @arr2 is small without many duplicates either, then it would appear that the above will iterate over the values of @arr1 twice. Also the above has the problem that the resulting array will have no ordering relationship to the original one. I think a superior method is the one I posted in my orphaned reply. Or rather a minor variant that doesn use hash slices.

my %remove; $remove{$_}++ for @arr2; @clean=grep !$remove{$_},@arr1;
This code will only walk @arr1 and @arr2 once. Note that this is one of the weaknesses in 'big O notation'. Both of these solutions are O(N), however, the worst cases of both are 2(N+M) and N+M, thus the later has a much better worst case even though they are the same order of solution.

BrowserUk posted a benchmark that I will mod to benchmark the various solutions, including the one above.

Regards,

--- demerphq
my friends call me, usually because I'm late....