Search code examples
perlhashdereference

Print dereferencing array inside hash of hash of array


My data structure looks like

%foo (
   'bar' => HASH(0x1staddr)
)

HASH(0x1staddr) is

%moo = (
   'doe' => ARRAY(0x2ndaddr)
    )

ARRAY(0x2ndaddr) points to str1 str2 str3 str4 str5

How can I dereference that ARRAY(0x2ndaddr) ?

Thanks.


Solution

  • So really,

    %foo = ( 'bar' => { 'doe' => [ 'str1', 'str2', 'str3', 'str4', 'str5' ] } ) ;
    

    First, I'd check out Data::Dumper which would print out all the levels of the structure for you without you having to put them back together.

    Second, you can dereference multiple levels in one line:

    print "$foo->{bar}{doe}[0]\n" ;
    

    would print:

    str1