Wednesday, July 21, 2010

Computing Union, intersection, or Diffrences of unique lists...

@a = (1, 3, 6, 7, 8);
@b = (2, 3, 5, 7, 9);

@union = @isect = ( );
%union = %isect = ( );

foreach $e (@a) {
$union{$e} = 1;
}

foreach $e2 (@b) {
if ($union{$e2} ) {
$isect {$e2} = 1;
}
$union{$e2} = 1;
}

@union = keys %union;
@isect = keys %isect;

No comments:

Post a Comment