title: Hash Efficiency with tons of data
body: <p>I have data like this:</p>
  
  <pre><code>1 10
  1 30
  1 40
  1 10
  2 20
  2 20
  2 30
  3 50
  3 10
  3 10
  3 10
  4 20
  4 10
  </code></pre>
  
  <p>I would like to sum all the values up IF the value of first column matches, the result would be like this,</p>
  
  <pre><code>1 90
  2 70
  3 80
  4 30
  </code></pre>
  
  <p>I have my code here,</p>
  
  <pre><code>while (&lt;DATA&gt;) 
  {
  my ($a, $b) = split;
  $hash{$a}  += $b;
  }
  
  foreach $a (sort keys %hash) 
  {
  $b = $hash{$a};
  print OUT "$a $b\n";
  }
  </code></pre>
  
  <p>It works with sample data (around 100MB) but it seems to take ages to deal with my real data (around 100G). Are there any ways to optimize my codes?</p>
  
  <p>Appreciate any advises in advance!</p>