in reply to subtract one array from another

I believe you're seeking splice.

-- Dan

Replies are listed 'Best First'.
Re^2: subtract one array from another
by Aristotle (Chancellor) on Oct 17, 2002 at 14:22 UTC
    Unfortunately, splice is itself an O(n) "loop", so by using it in a nested loop, you are writing an O(n3) algorithm. Even for a 20 and 5 element array, respectively, it's going to take several hundred operations - not exactly the best approach. Using a hash is better - it will run in linear time.

    Makeshifts last the longest.

      I did not know that at all! thanks! perhaps the documentation should mention this someplace? Or does it already - I was not able to find any reference.

      -- Dan

        I hadn't seen this in any of the docs or books, I only learned about it here in the monastery myself. In hindsight it is relatively obvious if you think about how arrays work, but being used to similar operations in constant time from hashes, it is easy to wrongly assume splice works the same way and I fell for the trap. It's sort of funny how nearly everyone does.

        Makeshifts last the longest.