in reply to Calculations using values from two different hashes
foreach my $date (keys %counts){ my $overallcount = $overallcounts{$date}; foreach my $word (keys %{$counts{$date}}){ $counts{$date}{$word."_average"} = sprintf("%.2f", 100 * $counts{$ +date}{$word} / $overallcount); } $counts{$date}{"_overallcount"} = $overallcount; } print Dumper \%counts;
Which yields:
$VAR1 = { '2017-09-30' => { 'c' => 1, 'b' => 2, 'a_average' => '57.14', '_overallcount' => 7, 'b_average' => '28.57', 'c_average' => '14.29', 'a' => 4 }, '2017-09-04' => { 'd' => 1, 'c_average' => '18.18', '_overallcount' => 11, 'b' => 3, 'a' => 5, 'b_average' => '27.27', 'd_average' => '9.09', 'c' => 2, 'a_average' => '45.45' } };
You can then replace {$word."_average"} with {$word} to overwrite the original values.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Calculations using values from two different hashes
by Maire (Scribe) on Nov 25, 2017 at 13:13 UTC | |
by syphilis (Archbishop) on Nov 25, 2017 at 13:28 UTC | |
by Maire (Scribe) on Nov 25, 2017 at 13:30 UTC | |
by Discipulus (Canon) on Nov 25, 2017 at 13:34 UTC | |
by Maire (Scribe) on Nov 26, 2017 at 09:11 UTC |