in reply to Re^2: How best to replicate/copy a hash of hashes
in thread How best to replicate/copy a hash of hashes
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How best to replicate/copy a hash of hashes
by flexvault (Monsignor) on Oct 05, 2010 at 11:48 UTC | |
by Marshall (Canon) on Oct 05, 2010 at 15:48 UTC |