title: Why can't I push items into a hash of arrays, in Perl?
body: <p>What I want here is for @{$allHash{$key1}} to be [&quot;item1&quot;, &quot;item2&quot;].</p>
  <p>Pushing doesn't work, and all the print statements are to try and find where the pushed items went.
  Using -&gt; notation in the push is even worse, it makes $temp[0][0] and line 24 show an array instead of the item.</p>
  <pre><code>    #use strict;   # I've turned these off here to make the code easier to read
      #use warnings;
  
      my %allHash = ();
      my $key1 = &quot;key1&quot;;
      my $item1 = &quot;item1&quot;;
      my $item2 = &quot;item2&quot;;
      #if (!exists($allHash{key1})) {$allHash{key1}=();}; # makes no difference, the array autovivefies anyway
  
      push (@{$allHash{$key1}},  $item1);         # push 1st item
      print&quot;\n\nat11: pushed $key1, $item1&quot;;
      my @temp = $allHash{$key1};
      print&quot;\nat13:temp=@temp, length=&quot;,0+@temp, &quot;, temp[0]=$temp[0], temp[0][0]=$temp[0][0]&quot;;
      print&quot;\nat14: allHash{$key1}[0]= $allHash{$key1}[0]&quot;;
      print&quot;\nat15: allHash{$key1}[1]= $allHash{$key1}[1]&quot;;
      print&quot;\nat16: allHash{$key1}[0][0]= $allHash{$key1}[0][0]&quot;;
      print&quot;\nat17: allHash{$key1}[1][0]= $allHash{$key1}[1][0]&quot;;
      print&quot;\nat18: allHash{$key1}[0][1]= $allHash{$key1}[0][1]\n&quot;;
      print&quot;\n----------------&quot;;
      
      push (@{$allHash{$key1}},  $item2);         # push 2d item
      print&quot;\n\nat21: pushed $key1, $item2&quot;;
      @temp = @{allHash{$key1}};
      print&quot;\nat23:temp=@temp, length=&quot;,0+@temp, &quot;, temp[0]=$temp[0], temp[0][0] =$temp[0][0]&quot;;
      print&quot;\nat24: allHash{$key1}[0]= $allHash{$key1}[0]&quot;;
      print&quot;\nat25: allHash{$key1}[1]= $allHash{$key1}[1], allHash{$key1}[1][0] =$allHash{$key1}[1][0]&quot;;
      print&quot;\nat26: allHash{$key1}[0][0]= $allHash{$key1}[0][0]&quot;;
      print&quot;\nat27: allHash{$key1}[1][0]= $allHash{$key1}[1][0]&quot;;
      print&quot;\nat28: allHash{$key1}[0][1]= $allHash{$key1}[0][1]\n&quot;;
  </code></pre>
  <p>The output from the above program is:</p>
  <pre><code>at11: pushed key1, item1
  at13:temp=, length=1, temp[0]=ARRAY(0x331eb8), temp[0][0]=item1
  at14: allHash{key1}[0]=item1
  at15: allHash{key1}[1]=
  at16: allHash{key1}[0][0]=
  at17: allHash{key1}[1][0]=
  at18: allHash{key1}[0][1]=
  
  ----------------
  
  at21: pushed key1, item2
  at23:temp=ARRAY(0x331ee8), length=1, temp[0]=ARRAY(0x331ee8), temp[0][0]=item1
  at24: allHash{key1}[0]=item1
  at25: allHash{key1}[1]= ARRAY(0x332020), allHash{key1}[1][0]=
  at26: allHash{key1}[0][0]=
  at27: allHash{key1}[1][0]=
  at28: allHash{key1}[0][1]=
  </code></pre>
  <p>What's bizarre is that this almost identical code from another of my programs works perfectly.</p>
  <pre><code>%hedgeHash = ();    # collect the members of each hedge as an array, using stub as key
  for (my $i=0; $i&lt;@options; $i++)
  {   $Hstub = $options[$i][$iStub];
      push @{$hedgeHash{$Hstub}}, $i; # hedgehash should contain array of members of the hedge.
  }
  </code></pre>
  <p>What's even more bizarre is that if I remove the parentheses from the push statement, I no longer get 'item1' as the output of @temp and on lines 14 and 24, but get another array! WTF??</p>