in reply to How can I find the union/difference/intersection of two arrays?

This is inefficient, but I use it for intersection when I know I'm guaranteed small list sizes, and it's more valuable / pleasing to me to have a one-line solution:

my @isect = map { my $b = $_; grep { $_ eq $b } @a } @b;
  • Comment on Re: How can I find the union/difference/intersection of two arrays?
  • Download Code

Replies are listed 'Best First'.
Re: Answer: How can I find the union/difference/intersection of two arrays?
by Anonymous Monk on Nov 16, 2017 at 16:10 UTC

    the problem with that method is that your @isect can contain identical elements

    for example,if @a=(1,2,3,4,2) and @b=(1,2,4), your @isect will be: (1,2,2,4)

    before using this method you have to make sure each element is unique in both tab