Thanks for clearing that up. I think I'm on the right track. What I want to do is add the total words for each section. I am trying to stay within th loop and do the following
%cntr = (
word1 => {
title1 => count1,
title2 => count1,
},
word2 => {
title1 => count2 + count1,
title2 => count2 + count1,
}
etc etc
so that when I end on the last word I will have the total words for each section and I can include that in my output as the last line. Basically I am trying to figure out how to add up all the values for title1, title2, and so on. Should I push all the values to an array then add them. Below totals the number of words in all sections (I already added that before by accident).
#print hash of hashes
foreach my $word ( sort keys %cnter ) {
print FILEOUT2 "$word : ";
my $cnter2 = 0;
for my $sect ( keys %{ $cnter{$word} } ) {
print FILEOUT2 "$sect = $cnter{$word}{$sect}\n";
$cnter2 += $cnter{$word}{$sect};
print FILEOUT2 $cnter2;
}
print FILEOUT2 " \n";
}
By moving where I declare $cnter2 I see how to add all the words in all the sections. I'm missing the next step to add all the words for 1 section.