title: Arithmetic operations between 2 hash arrays
body: <p>I have a hash array with a YAML, which was taken from a linux command. I have another hash array, with the same YAML set, but with different values, by the same command, which was run at a later time. </p>
  
  <p>Eg.</p>
  
  <pre><code>content.none: 
    bytes:  31046
  content.image.gif: 
    bytes:  0
  </code></pre>
  
  <p>and</p>
  
  <pre><code>content.none: 
    bytes:  31050
  content.image.gif: 
    bytes:  0
  </code></pre>
  
  <p>Now, I am looking for a math operation between the values. I am looking for an output </p>
  
  <pre><code>content.none: 
    bytes:  4
  content.image.gif: 
    bytes:  0
  </code></pre>
  
  <p>which is the result of math between the corresponding values in the hash.</p>
  
  <p>I tried iterating and doing diff, but it looks like a cumulative output.</p>
  
  <pre><code>%host_stat_new=New stats
   %host_stat_old=Old stats (taken from stats.yml, which contains old data)
  while (true){
  open my $FH1, "&gt;stats.yml" or die "cannot write to stat file because $!\n";
  foreach my $line4 (keys %host_stat_new){
          print $FH1 "$line4:\n";
          foreach my $line5 (keys %{$host_stat_new{$line4}}) {
                  print $FH1 "  $line5: \n";
                  foreach my $line6 (keys %{$host_stat_new{$line4}{$line5}}){
                  my $diff1 = $host_stat_new{$line4}{$line5}{$line6};
                  my $diff2 = $host_stat_old{$line4}{$line5}{$line6};
  
  
  $math=$diff1-$diff2;
  #$host_stat1{$line4}{$line5}{$line6} = $math;
  $host_stat_new{$line4}{$line5}{$line6} = $math;
                      print $FH1 "    $line6:  $host_stat_new{$line4}{$line5}{$line6}\n";
                      }
              }
  
  
      }
  }
  </code></pre>
  
  <p>What am I doing wrong here? Is there any module that can do this?</p>