Here's something to study.
#!/usr/bin/perl use Data::Dumper; # only for teaching purpose $Data::Dumper::Indent = 1; # dito :-) while(<DATA>) { chop; my($familyname,$memberstring) = split /\s--\s/,$_; my @members = split /, /,$memberstring; # tell each member that it's got a new family foreach my $member(@members) { push(@{$family{$member}},$familyname); } } print Dumper(\%family); # show the data structure in %family # now output a list of members with their families foreach my $member(sort keys %family) { print "$member can be found " . scalar(@{$family{$member}}) . ": " . join(" ", @{$family{$member}}) . "\n"; } __DATA__ FLINTSTONES -- BARNEY, FRED, WILMA JETSONS -- MAX, TONY, WILMA SIMPSONS -- LISA, BARNEY, WILMA, HOMER ALCATRAZ -- ELIJAH, MAX, WILMA
Download that code an run it; it will produce the following output:
$VAR1 = { 'ELIJAH' => [ 'ALCATRAZ' ], 'FRED' => [ 'FLINTSTONES' ], 'HOMER' => [ 'SIMPSONS' ], 'BARNEY' => [ 'FLINTSTONES', 'SIMPSONS' ], 'MAX' => [ 'JETSONS', 'ALCATRAZ' ], 'LISA' => [ 'SIMPSONS' ], 'WILMA' => [ 'FLINTSTONES', 'JETSONS', 'SIMPSONS', 'ALCATRAZ' ], 'TONY' => [ 'JETSONS' ] }; BARNEY can be found 2: FLINTSTONES SIMPSONS ELIJAH can be found 1: ALCATRAZ FRED can be found 1: FLINTSTONES HOMER can be found 1: SIMPSONS LISA can be found 1: SIMPSONS MAX can be found 2: JETSONS ALCATRAZ TONY can be found 1: JETSONS WILMA can be found 4: FLINTSTONES JETSONS SIMPSONS ALCATRAZ
If you need more advice or explanation, fell free to ask.

But before that - read the manual pages perldata, perlref and the one for Data::Dumper

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Counting/Matching Terms In Arrays contained within a Hash by shmem
in thread Counting/Matching Terms In Arrays contained within a Hash by sdslrn123

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.