ab323i has asked for the wisdom of the Perl Monks concerning the following question:

Hello All, I have 2 arrays and I want to compare the elements of the first one for their existance in the second one. If they elements don't exist in the second array, print it to another array. If using strict, how do you pass the arrays out of the loops? Thank you for any information.

Replies are listed 'Best First'.
Re: how to compare 2 array
by edan (Curate) on Oct 29, 2003 at 10:09 UTC
Re: how to compare 2 array
by rnahi (Curate) on Oct 29, 2003 at 13:03 UTC
Re: how to compare 2 array
by Hena (Friar) on Oct 29, 2003 at 10:09 UTC
    I would suggest making an hash from one array and testing that against the other (its a lot faster than what i could figure out with arrays).
    # @array1 and @array2 are what are tested my %test; map {$test{$_}=undef} @array1; my @result; foreach (@array2) { push (@result,$_) if (exists($test{$_})); }