> Are you trying to find the intersection of two arrays? I believe this
> is covered in the FAQ,


For simply finding the intersection of two arrays,  is there something wrong
with using nested greps?

I'm a Perl beginner and after reading the first post I wrote this:

my @arrA = qw( 1 3 5 6);
my @arrB = qw( 2 3 6 4);
my $tmp;

my @matches = grep { $tmp = $_;
                                  grep $tmp == $_, @arrB;
                                 } @arrA;

print join " ", @matches, "\n";

It prints out
3 6
for the above arrays.

I've read the perlfaq snippet and it seems to be more elegant and flexible.
I'd just like to know if there are any reasons, ie efficiency, I shouldn't
use nested greps on simple lists like the above.

As I said, I am a Perl beginner and only want to deepen my understanding
here so any comments would be greatly appreciated.

Thanks

Cornelis

Reply via email to