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 | |
by EdwardG (Vicar) on Apr 28, 2004 at 15:59 UTC |