Hello,

I have a problem, which I have put into an analogy.

Suppose a parent has 11 children. These children like chocolate. If 9 or more of the 11 children from the same parent like a particular chocolate, the parent will like the chocolate. I want to find out what types of chocolate each parent likes.

I have a file listing each child's preference of chocolate (which can be
= 1). There are +45,000 parents, each parent has 11 children and there
are +100,000 different types of chocolate.

I guess I could parse the file and store the results in something like this

$listOfParent{$parentOne}{$childOne} = @chocolate;
...
$listOfParent{$parentOne}{$childN} = @chocolate;
...
$listOfParent{$parentN}{$childN} = @chocolate;

Then

my %result = ();
foreach my $parent (keys %listOfParent){
   my $chocolate = '';
   foreach my $child (keys %{$listOfParent}{$parent}){
      foreach ($listOfParent{$parent}{$child}){
         $chocolate = $_;
         if (exists $result{$parent}{$chocolate}){
            $result{$parent}{$chocolate}++;
         } else {
            $result{$parent}{$chocolate} = '1';
         }
      }
   }
}

Then go through %result and print out the >=9. Is there a better way of doing this?

Cheers,

Dave

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to