code outputs perl code like data::dumper only more verbose (ready for copy/paste to access ) ex
#!/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__