title: Looping through hash of arrays in Perl
body: <p>I have a hash of arrays, as follows:</p>
  
  <pre><code>my %hash = (
  234 =&gt; ["Larry", "Curly", "Moe"],
  235 =&gt; ["bb", "ab", "aa", "ab", "bb"],
  236 =&gt; ["aa", "ab", "bb", "aa", "bb"],
  )
  </code></pre>
  
  <p>For each key in my hash, I would like to loop through each element of the array, assign that to a scalar variable so that I can process it, then move onto the next element of the array. Once I have processed all the elements of the array for a key, I want to onto the next key and individually process all of the elements of its array, and so on.</p>
  
  <p>I found and modified a snippet of code that iterates over the hash values (the array of each key in this case). Then I have a nested for-loop, that iterates over each element of that array. However, it's not doing what I expect it to.</p>
  
  <pre><code>for my $value (values %hash) {
      for (@$value) {
          my $index = shift($_);
         #process index
      }
  }
  </code></pre>
  
  <p><strong>Error Message</strong>
  Not an ARRAY reference at [line number]</p>
  
  <p>For example, for the first iteration, I want <code>$index</code> to equal <code>Larry</code> so that I can process it. Next iteration, I want <code>$index</code> to equal <code>Curly</code> so that I can process it. Next iteration, <code>$index</code> should equal <code>Moe</code>, process it. Next iteration, <code>$index</code> should equal <code>bb</code>, and so on. </p>
  
  <p>There may be a better function than <code>shift</code>. The <code>shift</code> function takes the first element off of the array. I want the hash of arrays to retain it's values so that I don't have to repopulate the hash of arrays.</p>
  
  <p>thanks</p>