in reply to Comparing two arrays
All that by your problem. As for comparing two arrays, and getting such things as 'the number of elements that exist in both arrays', have you looked at List::Compare ?package Frobcounting; sub new { my ($class, $a) = @_; my $h = {}; $h->{$_}++ for @$a; bless $h, $class; } sub new_d { my ($class, $a, $b) = @_; my $h = {}; my $h = { a => Frobcounting->new($a), b => Frobcounting->new($b) }; bless $h, $class; } sub frobcount { $_[0]->{$_[1]} } sub frobcount_d { my ($fc_d, $e) = @_; my $ea = $fc_d->{a}->frobcount($e); my $eb = $fc_d->{b}->frobcount($e); $ea < $eb ? $ea : $eb } sub smaller_d { my ($fc_d) = @_; my @ka = keys %{$fc_d->{a}}; my @kb = keys %{$fc_d->{b}}; @ka < @kb ? @ka : @kb } package main; my $fc = Frobcounting->new_d(\@string1, \@string2); for (sort $fc->smaller_d) { print "$_: ${\$fc->frobcount_d($_)}\n" }
|
|---|