mr_p has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I have a function that Compares 2 arrays and updates intersections of arrays and updates seconds arary only elements. My referencing for @bonly is getting screwed up. Can some one tell me why it is the case?
# Calling deDuppedArray(\@currentListing, \@previousListing, \@bonly, \@isec_plu +s_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 ta +ble 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 + f +rom A = Aonly push(@my_bonly, $e) unless exists $Aseen{$e}; # seen once ++ from A = Aonly } } @my_isec_plus_bonly = ( @isec, @my_bonly); }
|
---|