in reply to Need to Create an Array of Differences

Here's the hash way,

# given @a, @b my @c = do { my %a; @a{@a} = (); # slice of %a, values undef delete @a{@b}; # delete the @b slice keys %a; };
That may not be exactly what you want. If @a contains duplicate elements you wish to keep, this will not duplicate them in @c. If the order of @a is important, this will not preserve it in @c.

In those cases I would write code much like yours or Aristotle's or revdiablo's.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Need to Create an Array of Differences
by scottj (Monk) on Aug 03, 2004 at 02:13 UTC
    I ended up doing something like this:
    # given @a, @b my %a; @a{@a} = (); delete @a{@b}; my @c = keys %a;
    This code works just as well as my previous code with the exception that the new code is much faster. Thanks!

    -Scott

      I assume the code does what you need, but there are a few caveats that should be mentioned. This code will change the order of the values, and it will eliminate any duplicates. This may or may not be a problem, depending on what it's being used for.

      Update: these caveats were noted, in Zaxo's original node, I just failed to notice. My apologies.