Dave Tang <d.t...@imb.uq.edu.au> asked:
> my %result = (); > foreach my $parent (keys %listOfParent){ > my $chocolate = ''; > foreach my $child (keys %{$listOfParent}{$parent}){ > foreach ($listOfParent{$parent}{$child}){ > $chocolate = $_; Why not "foreach my $chocolate ($listOfParent{$parent}{$child}){"? > if (exists $result{$parent}{$chocolate}){ > $result{$parent}{$chocolate}++; > } else { > $result{$parent}{$chocolate} = '1'; > } You can just say "$result{$parent}{$chocolate}++;" - non-existing keys will be created automagically. If you don't need to know which child likes which chocolate later on, I would not bother with tracking that data. Just add the preference to the parents data while you're reading it from file. HTH, Thomas -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/