%count = ();
foreach $element (@A,@B)
{
$count{$element}++;
}
foreach $element (keys %count)
{
if ($count{$element} > 1) { push @intersection,$element; }
}
@A = (a 1 2 3 4);
@B = (a x y z);
@intersection = (a);
%count = ();
foreach $element (@A,@B)
{
$count{$element}++;
}
foreach $element (keys %count)
{
push @union,$element;
}
@A = (a 1 2 3 4);
@B = (a x y z);
@union = (1 2 3 4 a x y z);
@seen{@B} = ();
foreach (@A)
{
push (@difference, $_) unless exists $seen{$_};
}
@A = (a 1 2 3 4);
@B = (a x y z);
@difference = (1 2 3 4);
%count = ();
foreach $element (@A,@B)
{
$count{$element}++;
}
foreach $element (keys %count)
{
if ($count{$element} <= 1) { push @difference,$element; }
}
@A = (a 1 2 3 4);
@B = (a x y z);
@difference = (1 2 3 4 x y z);