Perl:YAML:Hash 如何选择一个条目? [英] Perl:YAML:Hash How to select an entry?
本文介绍了Perl:YAML:Hash 如何选择一个条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问候 Perl 专家
基于下面的 YAML 文件,以及这个例子 Perl:YAML 在数组中迭代?有人可以向我展示一个perl示例,我可以在其中选择国家并打印出我去过的城市吗?
Based on the YAML file below, and this example Perl:YAML iterate in the Array? can someone please be so kind to show me a perl example where i can select the countrie and print out the cities i have been?
USA:
BeenThere: [Miami, Denver, Las Vegas, Chicago]
ToVisit: [Los Angeles, Boston]
Europe:
BeenThere: [Paris, Amsterdam, Dublin, Bulgaria, Madrid]
ToVisit: [Budapest, Belgrad]
Latam:
BeenThere: [Venezuela, Bogota]
ToVisit: [Argentina, San Paulo]
非常感谢!
推荐答案
您想获取每个国家/地区的信息,还是仅获取特定国家/地区的信息?
Do you want to get the info for each country, or just a specific one?
具体的:
my $country_name = '...';
my $country = $data->{$country_name};
my $visited = $country->{BeenThere};
for my $city_name (@$visited) {
say $city_name;
}
全部:
for my $country_name (keys %$data) {
my $country = $data->{$country_name};
my $visited = $country->{BeenThere};
for my $city_name (@$visited) {
say "$city_name, $country_name";
}
}
这篇关于Perl:YAML:Hash 如何选择一个条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文