title: sum hash of hash values using perl
body: <p>I have a Perl script that parses an Excel file and does the following : It counts for each value in column A, the number of elements it has in column B, the script looks like this : </p>
  
  <pre><code>use strict;
  use warnings;
  use Spreadsheet::XLSX;
  use Data::Dumper;
  use List::Util qw( sum );
  
  my $col1 = 0;
  my %hash;
  
  my $excel = Spreadsheet::XLSX-&gt;new('inout_chartdata_ronald.xlsx');
  
  
  my $sheet = ${ $excel-&gt;{Worksheet} }[0];
  
  
  $sheet-&gt;{MaxRow} ||= $sheet-&gt;{MinRow};
  my $count = 0;
  # Iterate through each row
  foreach my $row ( $sheet-&gt;{MinRow}+1 .. $sheet-&gt;{MaxRow} ) {
  
  # The cell in column 1
  my $cell = $sheet-&gt;{Cells}[$row][$col1];
  
  if ($cell) {
  
      # The adjacent cell in column 2
      my $adjacentCell = $sheet-&gt;{Cells}[$row][ $col1 + 1 ];  
      # Use a hash of hashes
  
      $hash{ $cell-&gt;{Val} }{ $adjacentCell-&gt;{Val} }++;
  
  }
  }
  print "\n", Dumper \%hash;
  </code></pre>
  
  <p>The output looks like this : </p>
  
  <pre><code>$VAR1 = {
        '13' =&gt; {
                  'klm' =&gt; 1,
                  'hij' =&gt; 2,
                  'lkm' =&gt; 4,
                },
        '12' =&gt; {
                  'abc' =&gt; 2,
                  'efg' =&gt; 2
                }
      };
  </code></pre>
  
  <p>This works great, my question is : How can I access the elements of this output $VAR1 in order to do : for value 13, klm + hij = 3 and get a final output like this : </p>
  
  <pre><code>$VAR1 = {
        '13' =&gt; {
                  'somename' =&gt; 3,
                  'lkm' =&gt; 4,
                },
        '12' =&gt; {
                  'abc' =&gt; 2,
                  'efg' =&gt; 2
                }
      };
  </code></pre>
  
  <p>So basically what I want to do is loop through my final hash of hashes and access its specific elements based on a unique key and finally do their sum.</p>
  
  <p>Any help would be appreciated.
  Thanks</p>