Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Keep It Simple, Stupid
 
PerlMonks  

Re: How to access Hash of hashes with multi-dimensional Array

by 2teez (Priest)
on Apr 18, 2013 at 22:45 UTC ( #1029431=note: print w/ replies, xml ) Need Help??


in reply to How to access Hash of hashes with multi-dimensional Array

"..I want to access each and every element of the hash, How can I do that?.."
You can do like so:

use warnings; use strict; my %temp = ( "0x55555555" => { "0x55555555" => [ [ "0xAAAAAAAA", "0x9" ], ], "0xAAAAAAAA" => [ [ "0xAAAAAAAA", "0x8" ], ], }, "0xAAAAAAAA" => { "0x55555555" => [ [ "0xFFFFFFFF", "0x8" ], ], "0xAAAAAAAA" => [ [ "0x55555554", "0x3" ], ], }, ); foreach my $item ( keys %temp ) { print "$item: \n"; # print keys my $hash = $temp{$item}; foreach my $key2 ( keys %$hash ) { print "\t", $key2, "\n\t"; # print keys my $array = $hash->{$key2}; print "\t", join "\t", map { @$_ } @$array; # print all you +r values print "\n"; } }
OUTPUT:
0xAAAAAAAA: 0xAAAAAAAA 0x55555554 0x3 0x55555555 0xFFFFFFFF 0x8 0x55555555: 0xAAAAAAAA 0xAAAAAAAA 0x8 0x55555555 0xAAAAAAAA 0x9
Hope this helps.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: How to access Hash of hashes with multi-dimensional Array
Select or Download Code
Re^2: How to access Hash of hashes with multi-dimensional Array
by IamAwesom3 (Initiate) on Apr 19, 2013 at 14:33 UTC

    Thanks it did work but I want to use each element of array separately. like for example

    $temp{$hash}[0][1]
    how do I do that? I looked at the debugger option suggested by Tom. it did help but I am not able to write it in perl.

    and what will -> do in this code? my $array = $hash->{$key2};

    Thanks

    P

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029431]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-04-16 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (436 votes), past polls