gpt4 book ai didi

perl - 从 perl 哈希结构中获取数据?

转载 作者:行者123 更新时间:2023-12-02 07:45:22 24 4
gpt4 key购买 nike

我正在尝试修改现有的 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
]
}
}

已经尝试了我在谷歌上找到的所有哈希教程,我能打印的最多的是 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');

我只想要 Point -> 坐标数据到它自己的变量,然后我可以将其写入数据库。

最佳答案

这是你想要的吗?

$lon = $location->{Point}{coordinates}[0];
$lat = $location->{Point}{coordinates}[1];

关于perl - 从 perl 哈希结构中获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7442595/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com