# Calling deDuppedArray(\@currentListing, \@previousListing, \@bonly, \@isec_plus_bonly); #### sub deDuppedArray { my $a_ref = shift; # reference to input array A my @a = @$a_ref; # input array A my $b_ref = shift; # reference to input array B my @b = @$b_ref; # input array B my $bonly_ref = shift; # input array Bonly my @my_bonly = @$bonly_ref; # input array Bonly my $isec_plus_bonly_ref = shift; # input array isec_plus_bonly my @my_isec_plus_bonly = @$isec_plus_bonly_ref; # input array isec_plus_bonly my (%Aseen, %Bseen) = (); @Aseen{@a} = (); # lookup table @Bseen{@b} = (); # lookup table my (%count, @isec, @diff, @union, @aonly) = (); @my_bonly = (); # create null arrays foreach my $e (@a, @b) { $count{$e}++ } # put all items in hash table foreach my $e (keys %count) { # interate over each key of hash table push(@union, $e); # keys of hash table = union if ($count{$e} == 2) { push @isec, $e; # seen more than once = intersection } else { push @diff, $e; # seen once = difference push(@aonly, $e) unless exists $Bseen{$e}; # seen once + from A = Aonly push(@my_bonly, $e) unless exists $Aseen{$e}; # seen once + from A = Aonly } } @my_isec_plus_bonly = ( @isec, @my_bonly); }