Is there a way to calculate the total number of terms altogether within arrays of a hash. I know I have to divide the following scalar but I can't figure out how to group the total number of "family members" in all the "families" of the hash.
Code so far...
Data:
Ultimately I am looking to print:
Thanks for any kind of help or advice.
Code:
print "$member can be found " . scalar(@{$family{$member}}) / [b]?[/b] . ": "
Code so far...
Code:
#!/usr/bin/perl
use Data::Dumper;
$Data::Dumper::Indent = 1;
while(<DATA>) {
chop;
my($familyname,$memberstring) = split /\=/,$_;
my @members = split /, /,$memberstring;
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:
Code:
FLINTSTONES=BARNEY, FRED, WILMA
JETSONS=MAX, TONY, WILMA
SIMPSONS=LISA, BARNEY, WILMA, HOMER
ALCATRAZ=ELIJAH, MAX, WILMA
Code:
BARNEY can be found 2: FLINTSTONES SIMPSONS
BARNEY IS FOUND IN (2/Total)% of families
FRED can be found 1: FLINTSTONES
FRED IS FOUND IN (1/Total)% of families
e.t.c
Thanks for any kind of help or advice.