# Computation of Relationships between Two Lists in List::Compare's Regular Mode # Regular Mode => Compares only two lists; computes all relationships at once; # stores the results in a hash which is blessed into the List::Compare object. # Below: _init(), which is called by List::Compare's constructor and which returns # a reference to the hash which the constructor will bless. sub _init { my $self = shift; my ($unsortflag, $refL, $refR) = @_; my (%data, %seenL, %seenR); my @bag = $unsortflag ? (@$refL, @$refR) : sort(@$refL, @$refR); my (%intersection, %union, %Lonly, %Ronly, %LorRonly); my $LsubsetR_status = my $RsubsetL_status = 1; my $LequivalentR_status = 0; foreach (@$refL) { $seenL{$_}++ } foreach (@$refR) { $seenR{$_}++ } foreach (keys %seenL) { $union{$_}++; if (exists $seenR{$_}) { $intersection{$_}++; } else { $Lonly{$_}++; } } foreach (keys %seenR) { $union{$_}++; $Ronly{$_}++ unless (exists $intersection{$_}); } $LorRonly{$_}++ foreach ( (keys %Lonly), (keys %Ronly) ); $LequivalentR_status = 1 if ( (keys %LorRonly) == 0); foreach (@$refL) { if (! exists $seenR{$_}) { $LsubsetR_status = 0; last; } } foreach (@$refR) { if (! exists $seenL{$_}) { $RsubsetL_status = 0; last; } } $data{'seenL'} = \%seenL; $data{'seenR'} = \%seenR; $data{'intersection'} = $unsortflag ? [ keys %intersection ] : [ sort keys %intersection ]; $data{'union'} = $unsortflag ? [ keys %union ] : [ sort keys %union ]; $data{'unique'} = $unsortflag ? [ keys %Lonly ] : [ sort keys %Lonly ]; $data{'complement'} = $unsortflag ? [ keys %Ronly ] : [ sort keys %Ronly ]; $data{'symmetric_difference'} = $unsortflag ? [ keys %LorRonly ] : [ sort keys %LorRonly ]; $data{'LsubsetR_status'} = $LsubsetR_status; $data{'RsubsetL_status'} = $RsubsetL_status; $data{'LequivalentR_status'} = $LequivalentR_status; $data{'bag'} = \@bag; return \%data; }