code outputs perl code like data::dumper only more verbose (ready for copy/paste to access ) ex

$location->{address_components}[0]{types}[0] = "street_number"; #d3 $location->{address_components}[5]{short_name} = "CH"; #d2 $location->{geometry}{location_type} = "ROOFTOP"; #d1

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; my $location = my $VAR1 = { 'formatted_address' => 'Huoben 2, 6023 Rothenburg, Schweiz', 'types' => [ 'street_address' ], 'address_components' => [ { 'types' => [ 'street_number' ], 'short_name' => '2', 'long_name' => '2' }, { 'types' => [ 'route' ], 'short_name' => 'Huoben', 'long_name' => 'Huoben' }, { 'types' => [ 'locality', 'political' ], 'short_name' => 'Rothenburg', 'long_name' => 'Rothenburg' }, { 'types' => [ 'administrative_area_level_2', 'polit +ical' ], 'short_name' => 'Hochdorf', 'long_name' => 'Hochdorf' }, { 'types' => [ 'administrative_area_level_1', 'political' ], 'short_name' => 'LU', 'long_name' => 'Luzern' }, { 'types' => [ 'country', 'political' ], 'short_name' => 'CH', 'long_name' => 'Schweiz' }, { 'types' => [ 'postal_code' ], 'short_name' => '6023', 'long_name' => '6023' } ], 'geometry' => { 'viewport' => { 'southwest' => { 'lat' => '47.0860081197085', 'lng' => '8.2563233197085' }, 'northeast' => { 'lat' => '47.0887060802915', 'lng' => '8.2590212802915' } }, 'location' => { 'lat' => '47.0873571', 'lng' => '8.2576723' }, 'location_type' => 'ROOFTOP' } }; rehohy( $location, 0, '$location->' ); dd( $location->{geometry}{location_type} ); dd( $location->{geometry}{viewport}{northeast}{lng} ); dd( $location->{address_components}[4]{long_name} ); dd( $location->{address_components}[5]{types}[1] ); exit( 0 ); sub rehohy { use Data::Dump qw/ pp /; my( $hoh, $depth, $path, $callback ) = @_; $depth ||= 0; $path ||= ''; if( 'HASH' eq ref $hoh ) { while( my( $key, $val ) = each %$hoh ) { $key = pp( $key ) if $key =~ /\s|\W/; if( ref $val ) { rehohy( $val, $depth + 1, "$path\{$key}" ); } else { if( $callback ) { $callback->( $val, "$path\{$key}" ); } else { my $vall = pp( $val ); print "$path\{$key}\n", ( " " x $depth ), "= $vall; #d$depth\n\n"; } } } } elsif( 'ARRAY' eq ref $hoh ) { my $key = 0; for my $val ( @$hoh ) { if( ref $val ) { rehohy( $val, $depth + 1, "$path\[$key]" ); } else { if( $callback ) { $callback->( $val, "$path\[$key]" ); } else { my $vall = pp( $val ); print "$path\[$key]\n", ( " " x $depth ), "= $vall; #d$depth\n\n"; } } $key++; } } } ## end sub rehohy __END__

In reply to Re: Google decoder (how to access hash values, perl dereferencing string xpaths data dumper ) by Anonymous Monk
in thread Google decoder by bkerr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.