title: How do I update values in an array of hashes, which is in a hash of a hash in perl?
body: <p>Seems very confusing I know. I'll try to "draw" this data structure:</p>
  
  <p>hash-> key->( (key)->[(key,value),(key,value),(key,value),...],
                (key,value))</p>
  
  <p>So there is the first key, whose value is enclosed in the parenthesis. The value for the first key of the hash is two keys, one (the right one) being another simple key, value pair. The other (the left one) key's value is an array of hashes. I am able to update the "right" key, value pair with the following line of code:</p>
  
  <pre><code>$hash{$parts[1]}{"PAGES"} += $parts[2];
  </code></pre>
  
  <p>Where $parts[1] and $parts[2] are just elements from an array. I am +=ing a number to the "right" key, value pair from my hash. What I need to do now is update the "left" key,value pair - the array of hashes within a hash of hashes. Here is how I initialize the array for both key, value pairs in the hash of hashes:</p>
  
  <pre><code>$hash{$printer}{"PAGES"} = 0;
  $hash{$printer}{"USERS"} = [@tmp];
  </code></pre>
  
  <p>Here is one of my many attempts to access and update the values in the array of hashes:</p>
  
  <pre><code>$hash{$parts[1]}{"USERS"}[$parts[0]] += $parts[2];
  </code></pre>
  
  <p>I just can't figure out the correct syntax for this. If anyone could help me I'd appreciate it. Thanks.</p>
  
  <p>Edit: I guess a more pointed question is: How do I get a hash key from an array of hashes (keeping in mind that the array is in a hash of hashes)?</p>
  
  <p><strong>Edit:</strong> Added this to the code:</p>
  
  <pre><code>#Go through each user to check to see which user did a print job and add the page
  #count to their total
  #$parts[0] is the user name, $parts[1] is the printer name, $parts[2] is the page
  #count for the current print job
  for(my $i=0;$i&lt;$arr_size;$i++)
  {
      my $inner = $hash{$parts[1]}{"USERS"}[$i];
      my @hash_arr = keys %$inner;
      my $key = $hash_arr[0];
  
      #problem line - need to compare the actual key with $parts[0]
      #(not the key's value which is a number)
      if($hash{$parts[1]}{"USERS"}[$i]{$key} eq $parts[0])
      {
          $hash{$parts[1]}{"USERS"}[$i]{$parts[0]} += $parts[2];
      }   
  }
  </code></pre>
  
  <p><strong>Edit:</strong> Whoops hehe this is what I needed. It still isn't quite there but this is kind of what I am looking for:</p>
  
  <pre><code>if($key eq $parts[0])
  {
      $hash{$parts[1]}{"USERS"}[$i]{$parts[0]} += $parts[2];
  }
  </code></pre>