http://www.perlmonks.org?node_id=508127


in reply to how to dereference for the following hash of hash of arrays

In this structure:

{ (name => "command1", id=> "001"), (name => "command2", id=> "002"), (name => "command3", id=> "003"), (name => "command4", id=> "004") }

You were deceived by the visual efforts. It looks like that all four name/id pairs were independent, but actually not. They were all at the same flat level - eight key/value pairs. There is no difference between your structure and the following:

{ name => "command1", id=> "001", name => "command2", id=> "002", name => "command3", id=> "003", name => "command4", id=> "004" }

Which hopefully helps you to see that, for example, name was assigned to some different values four times, and each time overwrites the previous one, thus it is left with the last assigned value "command4". So now we are saying that your original structure is the same as:

{ name => "command4", id=> "004" }

But the following structure is different, and all four pairs of name/id can coexist:

{ [name => "command1", id=> "001"], [name => "command2", id=> "002"], [name => "command3", id=> "003"], [name => "command4", id=> "004"] }

Replies are listed 'Best First'.
Re^2: how to dereference for the following hash of hash of arrays
by Tanktalus (Canon) on Nov 13, 2005 at 19:05 UTC

    pg, I don't think that does the trick either. See my response. Try dumping that structure ... you'll get something like this:

    $VAR1 = { 'component1' => { 'ARRAY(0x816936c)' => [ 'name', 'command4', 'id', '004' ], 'ARRAY(0x813bf00)' => [ 'name', 'command2', 'id', '002' ] }, # ...
    Not what you want at all.