#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11111061 use warnings; my $month_total = 0; my $day_week_total = 0; my $VAR1 = { 'Adam' => { 'days' => 22, 'weeks' => 5, 'total' => 22 }, 'Keas' => { 'total' => 114, 'test' => 2, 'weeks' => 8, 'days' => 107, 'months' => 5 }, 'Tim' => { 'total' => 4, 'weeks' => 5, 'days' => 3, 'months' => 1 }, 'Sum' => { 'total' => 440, 'days' => 365, 'months' => 9 } }; for my $key ( grep $_ ne 'Sum', keys %$VAR1 ) { $month_total += ($VAR1->{$key}{months} // 0); $day_week_total += $VAR1->{$key}{days} + $VAR1->{$key}{weeks}; } print "month_total = $month_total day_week_total = $day_week_total\n";
In reply to Re: How to loop through hash of hashes and add the values based on condition?
by tybalt89
in thread How to loop through hash of hashes and add the values based on condition?
by Sami_R
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |