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" }
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 ?

In reply to Re: Comparing two arrays by ayrnieu
in thread Comparing two arrays by lampros21_7

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.