in reply to Comparing Two Arrays

To rephrase, you have two sets of data and you want to find the union - intersection. In other words, take elements that appear in either set and get rid of the elements that appear in only one set.

Using Set::Scalar, I would solve your problem as so:

use strict; use Set::Scalar; my $set1 = Set::Scalar->new( @array1 ); my $set2 = Set::Scalar->new( @array2 ); my $set3 = $set1->difference( $set2 )->union( $set2->difference( $set1 + ) ); my @array3 = $set3->members;

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Thanks (Re^2: Comparing Two Arrays)
by Anonymous Monk on Feb 23, 2005 at 23:00 UTC
    I noticed Mark's suggestion first, which was very similar to yours. I was working along happily, but then I got stuck because I needed the output as an array--not a scalar. Your reply helped me achieve the output I needed. $set3->members worked perfectly! Thanks for your help!

    Title edit by tye from just "Thanks"