Hashes of Hashes



Hi,
I'm working on a complex data structure with hashes of hashes and
hashes of arrays and I noticed a weird behavior I was hoping someone
could explain. Here's a sample:

$Data{US17}{1}{GROUP} = "STRING";
$Data{US17}{1}{GROUP}{.001} = 5;
$Data{US17}{1}{GROUP}{.002} = 6;
$Data{US17}{1}{GROUP}{.003} = 7;
print "group = $Data{US17}{1}{GROUP}\n";
for my $time (keys %{$Data{US17}{1}{GROUP}}){
print "time = $time $Data{US17}{1}{GROUP}{$time}\n";
}

The output is:
group = STRING
time = 0.002 6
time = 0.003 7
time = 0.001 5

If I swap the order of the declarations, then all of the keys for the
hash under 'GROUP' are wiped out. For example:
$Data{US17}{1}{GROUP}{.001} = 5;
$Data{US17}{1}{GROUP}{.002} = 6;
$Data{US17}{1}{GROUP}{.003} = 7;
$Data{US17}{1}{GROUP} = "STRING";

only produces:
group = STRING

Is this expected behavior? Am I getting lucky in the first instance
with bad syntax that just happens to do what I want?

Thanks in advance,
Jason
.



Relevant Pages

  • Re: Idiot Q: How to find index number of HASH match?
    ... Here are two hash tables, ... Hashes don't have 'links'. ... Hashes do not have index numbers and they don't have arrays. ... least) two choices for keeping your hash keys in order: ...
    (comp.lang.perl.misc)
  • Re: adding data to a file before it gets regexed
    ... hashes, but I am open to using them. ... The reasion I am trying to add the string to the line, is so that I can use ... it is not a good idea to store entire files in memory and it is really ... the arrays are the contents of the files broken down by lines. ...
    (perl.beginners)
  • Re: A neat trick to serialize arrays and hashes
    ... The serialized string will most likely contain ... This technique only handles simple arrays and hashes. ... > an array of these serialized arrays, ...
    (comp.lang.perl.misc)
  • Re: Boolschen Kontext forcieren
    ... > Bei Strings ist der leere String false, ... > Arrays und Hashes werden im skalaren Kontext interpretiert. ... Kontext ausgewertet wird. ...
    (de.comp.lang.perl.misc)
  • Re: [fw-wiz] Stanford break in
    ... > number and a special character.) ... > change the hash and make it harder for brute force to check. ... a password cracker takes strings and hashes them.. ... you gotta burn MORE cycles producing hashes from each string. ...
    (Firewall-Wizards)