Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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 chilling in the Monastery: (7)
As of 2019-10-22 03:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?