in reply to hash of hash - incorrect values?

$Stats{$DestPort}++; $Stats{$DestPort}{covert}{$intSrcFound| $hshIPtoDomainIndex{$strDst}|$ +DstIP|$SrcIP|$DestPort|$Protocol"}++;

This doesn't make much sense. $Stats{$DestPort} can only be one thing at a time. In the first line you are incrementing a presumably numeric value, in the next line you are assigning a reference to a deep nested structure.

Replies are listed 'Best First'.
Re^2: hash of hash - incorrect values?
by NathanE (Beadle) on Aug 03, 2005 at 19:33 UTC
    I guess that's part of my question. Can a lower level of a hash contain a value and also be linked to other levels of hashes? I thought they could, but maybe not?

    If they can't, than I don't understand how I am obtaining values at all, both for the incremented integer and also for the key and the related value in the deeply nested structure.

    comments?

      You misunderstand $hash{a}{b}. Hashes only have one level. $hash{a}{b} is a hash of a hash. $hash{a}{b} is a shortcut for ${$hash{a}}{b}. That means "the value at key 'b' in the hash referenced by $hash{a}." $hash{a} can't contain both a hash reference and a number, so $hash{a}++ and $hash{a}{b} conflict.

      There is an easy solution. Replace

      $Stats{$DestPort}++; $Stats{$DestPort}{covert}{"..."}++;

      with

      $Stats{$DestPort}{total}++; $Stats{$DestPort}{covert}{"..."}++;

      or

      $Stats{$DestPort}{total}++; $Stats{$DestPort}{item}{covert}{"..."}++;