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

slatibart has asked for the wisdom of the Perl Monks concerning the following question:

This is probably a very easy question to answer but gives me headache. I have trouble to access a datastructure . This is what Data::Dumper tells me How do I access the DOMAIN structure correctly ?
$VAR1 = { 'QUEUETIME' => '0.046', 'PROPERTY' => { 'DOMAIN' => [ 'a.com', 'b.com', 'c.com' ], 'LIMIT' => [ '1000' ], } };
So that I could do something like this : for(@domains) {..}

Replies are listed 'Best First'.
Re: Datastructure access
by toolic (Bishop) on Oct 27, 2014 at 13:54 UTC
    One way to dereference the array:
    use warnings; use strict; my %data = ( 'QUEUETIME' => '0.046', 'PROPERTY' => { 'DOMAIN' => [ 'a.com', 'b.com', 'c.com' ], 'LIMIT' => [ '1000' ], } ); my @domains = @{ $data{PROPERTY}{DOMAIN} }; for (@domains) { print "$_\n"; } # Same w/out intermediate array: # print "$_\n" for @{ $data{PROPERTY}{DOMAIN} }; __END__ a.com b.com c.com

    See also:

      Thank you very much. Helped me to understand a fundamental mistake I had.