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

    Indeed.

    If this were twenty-five years ago, when:

    • “Google” was a very big number and nothing more, and ...
    • People actually went to libraries, and ...
    • Libraries had card-catalogs ...
    then I would suggest the analogy that “the book itself” is over there on the shelf, while “the index card or cards that refer to that book” are right here in the various drawers.   Many cards may refer to the same book, and you can make more such cards any time you like (with the librarian’s permission, of course...), but there will still be only one book.

    You can build arbitrary data structures in Perl ... but what you are actually doing is moving-around those index cards, not the books themselves.   Perl will take you directly to the book when you use an index-card that refers to it.   Just remember that several cards can refer to the same book, and clearly keep in mind the difference between “the book” and “the card.”

    You might think of it as a Hogwarts index-card, though, because if you scribble on the index-card, a mark magically shows up on the book, and therefore every other index-card simultaneously shows the mark.   Be careful when fooling around with magic.