http://qs321.pair.com?node_id=1141183


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:  <%-{-{-{-<