Update: Anyway $Account{"0"} is a reference to a hash. The purpose of this is to create a new hash and "take out one level of hash key" which is a reference. $Account{$i}{$key} should be a scalar and likewise $TAccount{$key} should be a scalar - the {$i} keys are "gone". I still think something is a bit weird with the code below, but I think I grok the idea of what is supposed to happen.
print "\nB:Acct: ",\%Account,"\t",\$Account{"0"},"\t", \$Account{"1"},"\t",\$Account{"10"},"\n"; ####### { #I'm guessing this is a typo ???? ####### my %TAccount = (); keys( %TAccount ) = $i; foreach my $key ( keys %{ $Account{$i} } ) { $TAccount{$key} = $Account{$i}{$key}; } print "A:TAcct1: ",\%TAccount,"\t",\$TAccount{"0"}, "\t",\$TAccount{"1"}, "\t",\$TAccount{"10"},"\n"; print "\nB:Acct: ",\%Account,"\t",\$Account{"0"}, "\t",\$Account{"1"}, "\t",\$Account{"10"},"\n"; { #### this does nothing!!! ##### #### except hide the previous %TAccount my %TAccount = %{ $Account{"$i"} }; print "A:TAcct2: ",\%TAccount,"\t",\$TAccount{"0"}, "\t",\$TAccount{"1"}, "\t",\$TAccount{"10"},"\n";
In reply to Re^3: How best to replicate/copy a hash of hashes
by Marshall
in thread How best to replicate/copy a hash of hashes
by flexvault
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |