in reply to comparing arrays

...so that I can then compare this new array with a third array and repeat the process

To determine what elements are common to a set of arrays you should use hashes, since that is the mechanism best suited to checking if values have previously been encountered.

$h{$_}++ for (@array1,@array2); @common_elements = grep {$h{$_} > 1} keys %h; print "@common_elements";

With a little imagination you could make this generic to operate on N arrays, not just two.

Replies are listed 'Best First'.
Re: Re: comparing arrays
by eric256 (Parson) on Apr 28, 2004 at 15:39 UTC

    This breaks if the one array has multiple occurences of the same elements. Of course we don't konw what the requirments are from the specs.


    ___________
    Eric Hodges

      That's right, it assumes that each element is unique in a given array, just like the version in the faq.