in reply to Parsing a JSON response

$VAR1->{'address_components'}->[4]->{'long_name'}

works for me...

Hope that helps....

Update:I think that you are seeing {'address_components'} as part of the 'types' data sub-structure. It is not. "types' is a hash key at the same structural level as the hash key 'address_components'. In other words, both are keys in the same hash. 'types' references an array containing locality and political. 'address_component' references an array of hashes, one of which seems to be a duplicate of the array pointed at by the aforementioned 'types' key...

...the majority is always wrong, and always the last to know about it...

Insanity: Doing the same thing over and over again and expecting different results...

A solution is nothing more than a clearly stated problem...otherwise, the problem is not a problem, it is a facct

Replies are listed 'Best First'.
Re^2: Parsing a JSON response
by GrandFather (Saint) on Jul 25, 2014 at 19:55 UTC

    Note that that can be written:

    $VAR1->{address_components}[4]{long_name}

    which is more consistent with the OP's usage and reads better (at least to my eye) because it reduces clutter.

    Perl is the programming world's equivalent of English
Re^2: Parsing a JSON response
by mcoblentz (Scribe) on Jul 25, 2014 at 18:24 UTC
    Ah, enlightenment. I kept trying things like {type[4]}but that wasn't getting me anywhere. Thank you!
Re^2: Parsing a JSON response
by mcoblentz (Scribe) on Jul 25, 2014 at 22:20 UTC
    I don't yet follow you but I am hanging on with everything I have.

    If both "address_components' AND 'types' are keys within the same hash, then what is the value pair for 'address_components'? I'm having trouble wrapping my head around that... Indeed, I thought types was a substructure within 'address_components'...

      Does this rehohy output help?

      my $VAR1; $VAR1->{formatted_address} = "Johannesburg, South Africa"; #d0 $VAR1->{types}[0] = "locality"; #d1 $VAR1->{types}[1] = "political"; #d1 $VAR1->{address_components}[0]{types}[0] = "locality"; #d3 $VAR1->{address_components}[0]{types}[1] = "political"; #d3 $VAR1->{address_components}[0]{short_name} = "Johannesburg"; #d2 $VAR1->{address_components}[0]{long_name} = "Johannesburg"; #d2 $VAR1->{address_components}[1]{types}[0] = "administrative_area_level_3"; #d3 $VAR1->{address_components}[1]{types}[1] = "political"; #d3 $VAR1->{address_components}[1]{short_name} = "Johannesburg"; #d2 $VAR1->{address_components}[1]{long_name} = "Johannesburg"; #d2 $VAR1->{address_components}[2]{types}[0] = "administrative_area_level_2"; #d3 $VAR1->{address_components}[2]{types}[1] = "political"; #d3 $VAR1->{address_components}[2]{short_name} = "City of Johannesburg Metropolitan Municipality"; #d2 $VAR1->{address_components}[2]{long_name} = "City of Johannesburg Metropolitan Municipality"; #d2 $VAR1->{address_components}[3]{types}[0] = "administrative_area_level_1"; #d3 $VAR1->{address_components}[3]{types}[1] = "political"; #d3 $VAR1->{address_components}[3]{short_name} = "GP"; #d2 $VAR1->{address_components}[3]{long_name} = "Gauteng"; #d2 $VAR1->{address_components}[4]{types}[0] = "country"; #d3 $VAR1->{address_components}[4]{types}[1] = "political"; #d3 $VAR1->{address_components}[4]{short_name} = "ZA"; #d2 $VAR1->{address_components}[4]{long_name} = "South Africa"; #d2 $VAR1->{geometry}{viewport}{southwest}{lat} = -26.2389231; #d3 $VAR1->{geometry}{viewport}{southwest}{lng} = 27.942449; #d3 $VAR1->{geometry}{viewport}{northeast}{lat} = -26.1041199; #d3 $VAR1->{geometry}{viewport}{northeast}{lng} = 28.1376001; #d3 $VAR1->{geometry}{location}{lat} = -26.2041028; #d2 $VAR1->{geometry}{location}{lng} = 28.0473051; #d2 $VAR1->{geometry}{location_type} = "APPROXIMATE"; #d1 $VAR1->{geometry}{bounds}{southwest}{lat} = -26.2389231; #d3 $VAR1->{geometry}{bounds}{southwest}{lng} = 27.942449; #d3 $VAR1->{geometry}{bounds}{northeast}{lat} = -26.1041199; #d3 $VAR1->{geometry}{bounds}{northeast}{lng} = 28.1376001; #d3

      See also references quick reference

      see also

      chromatics free book Modern Perl a loose description of how experienced and effective Perl 5 programmers work....You can learn this too.
      Learn Perl in about 2 hours 30 minutes

        Yes... and no. I have to study this. I may be thinking a bit too old-fashioned - a 2D array but more like rows and columns (not in any particular order). Thanks for the help - I have my homework to do!