Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: JSON and Perl Objects - How to access data?

by Anonymous Monk
on Sep 06, 2015 at 04:35 UTC ( [id://1141183]=note: print w/replies, xml ) Need Help??


in reply to Re^3: JSON and Perl Objects - How to access data?
in thread JSON and Perl Objects - How to access data?

Wow- that is awesome. Thank you for the well commented answer. I really appreciate it.

I'm going to have to wrap my head around

say ${ $obj->{'items'}->[1] }{'name'};

but other than that I'm there. Thanks again!

Replies are listed 'Best First'.
Re^5: JSON and Perl Objects - How to access data?
by AnomalousMonk (Archbishop) on Sep 06, 2015 at 13:04 UTC

    See also the Data Structures Cookbook.

    I'm going to have to wrap my head around ...

    One way to go about that is to dump (see Data::Dumper; see also Data::Dump) the Perl object reference in stages, and from the inside out (i.e., top level to bottom):
        print Dumper $obj->{'items'};
    will show that you have a reference to an array. Then
        print Dumper $obj->{'items'}->[1];
    will show that one element of the array contains a hash reference. Finally,
        print Dumper ${ $obj->{'items'}->[1] }{'name'};
    will show the value of one key of the referent.

    Update: BTW: the expression
        ${ $obj->{'items'}->[1] }{'name'}
    is equivalent to the more concise and IMHO preferable
        $obj->{'items'}[1]{'name'}


    Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-24 14:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found