Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Datastructure access

by slatibart (Sexton)
on Oct 27, 2014 at 13:49 UTC ( #1105152=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2020-09-26 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (141 votes). Check out past polls.

    Notices?