in reply to RFC How to retrieve a hash from a hash of hashes
... extract an individual's record ... and assign it to a hash [to send] to a subroutine for processing ... "extract hash from hash of hashes and assign it to its own hash" ... retrieve an individual record ...
These invocations of 'individuality' lead to a sneaking suspicion of the notion of isolation.
The thing to remember about Perl complex data structures is that below the top-most level, it's references all the way down. And, of course, "a reference does what a reference do".
In other words, the copy operations bdalzell shows in the OP (or should that be the OM: Original Meditation?) are 'shallow' copies: all the references involved still go trailing back to their original referents. (An example of this shown below.) Given this is the case, I find it is usually easier and less potentially self-deceptive to simply extract and pass around the references themselves rather than trying to make 'copies' of them.
>perl -wMstrict -le "use Data::Dumper; ;; my %HoH = ( foo => { bar => { baz => { quux => 42, }, }, }, ); print Dumper \%HoH; ;; my %my_own_bar = %{ $HoH{foo}{bar} }; $my_own_bar{baz}{quux} = 'OOPS'; print Dumper \%my_own_bar; print Dumper \%HoH; " $VAR1 = { 'foo' => { 'bar' => { 'baz' => { 'quux' => 42 } } } }; $VAR1 = { 'baz' => { 'quux' => 'OOPS' } }; $VAR1 = { 'foo' => { 'bar' => { 'baz' => { 'quux' => 'OOPS' } } } };
You have been warned.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RFC How to retrieve a hash from a hash of hashes
by locked_user sundialsvc4 (Abbot) on Jan 13, 2012 at 15:22 UTC |