Osk*_*emi 2 perl hash perl-data-structures
我正在尝试修改现有的perl脚本以支持地理编码.找到了这个模块:http://metacpan.org/pod/Geo :: Coder :: Google
我只是无法弄清楚如何从它返回的哈希结构中提取数据(我不是一个perl编码器,这只是我必须解决的一些遗留脚本).
{
'AddressDetails' => {
'Country' => {
'AdministrativeArea' => {
'SubAdministrativeArea' => {
'SubAdministrativeAreaName' => 'San Francisco',
'Locality' => {
'PostalCode' => {
'PostalCodeNumber' => '94107'
},
'LocalityName' => 'San Francisco',
'Thoroughfare' => {
'ThoroughfareName' => '548 4th St'
}
}
},
'AdministrativeAreaName' => 'CA'
},
'CountryNameCode' => 'US'
}
},
'address' => '548 4th St, San Francisco, CA 94107, USA',
'Point' => {
'coordinates' => [
'-122.397323',
'37.778993',
0
]
}
}
Run Code Online (Sandbox Code Playgroud)
尝试过我在google上找到的所有哈希教程,我能用它打印的最多就像HASH(0x91e5558).到目前为止,我的代码是模块显示的示例:
use Geo::Coder::Google;
my $geocoder = Geo::Coder::Google->new(apikey => 'Your API Key');
my $location = $geocoder->geocode( location => 'Hollywood and Highland, Los Angeles, CA');
Run Code Online (Sandbox Code Playgroud)
我只想要Point - >坐标数据到它自己的变量然后我可以写入数据库.
这是你想要的吗?
$lon = $location->{Point}{coordinates}[0];
$lat = $location->{Point}{coordinates}[1];
Run Code Online (Sandbox Code Playgroud)