title: Delete value from Perl hash of arrays of hashes
body: <p>I'm trying to delete values from a hash of arrays of hashes that I created with the following code:</p>
  
  <pre><code>while ((my $Genotype1, my $Fitness1) = each (%Normalisedfithash)) {
    while ((my $Parent1A, my $TallyP1) = each(%P1Tallyhash)) {
      my $ParentTally = 0;
      my $SecondParent = {
        Parent2 =&gt; $Parent1A,
        Tally =&gt; $ParentTally,
      };
      push @{ $StoredParentshash{$Genotype1}}, $SecondParent;
  </code></pre>
  
  <p>I have been trying to delete values from <code>%StoredParentshash</code> where <code>Tally</code> is zero. (I have further code which updates <code>Tally</code>, but some are not updated and I want them removed from the hash).</p>
  
  <p>I have written the following:</p>
  
  <pre><code>for my $Parent (keys %StoredParentshash) {
    my $aref1 = $StoredParentshash{$Parent};
    for my $hashref1 (@$aref1) {
      my $Tally =  $hashref1-&gt;{'Tally'};
      if ($Tally == 0){
        delete $hashref1-&gt;{'Tally'};
        delete $hashref1-&gt;{'Parent2'};
      }
    }
  }
  </code></pre>
  
  <p>This code sort of deletes the data, but when I use <code>Data::Dumper</code> the structure I get back looks like this:</p>
  
  <pre><code> '7412' =&gt; [
          {},
          {
            'Tally' =&gt; 1,
            'Parent2' =&gt; '2136'
          },
          {},
          {},
          {},
  </code></pre>
  
  <p>How can I completely remove the keys where the <code>Tally</code> is zero rather than being left with <code>{}</code>?</p>
  
  <p>Thanks!</p>