在另一个线程中,给出了如何访问特定键的具体示例。无论如何,在编写可以访问任意键的子代码时是否有已知的最佳实践?例如,sub get_lat
将是一个具体的属性 - 纬度。但请关注更通用的选项,例如sub get_value_by_keys($$$)
. &get_value_by_keys(bounds,northeast,lat)
会回来51.4770228
的。
address_components => [
{
long_name => "Blackheath Avenue",
short_name => "Blackheath Ave",
types => ["route"],
},
{
long_name => "Greater London",
short_name => "Gt Lon",
types => ["administrative_area_level_2", "political"],
},
{
long_name => "United Kingdom",
short_name => "GB",
types => ["country", "political"],
},
{
long_name => "SE10 8XJ",
short_name => "SE10 8XJ",
types => ["postal_code"],
},
{
long_name => "London", short_name => "London", types => ["postal_town"]
},
],
formatted_address => "Blackheath Avenue, London SE10 8XJ, UK",
geometry => {
bounds => {
northeast => { lat => 51.4770228, lng => 0.0005404 },
southwest => { lat => 51.4762273, lng => -0.0001147 },
},
location => { lat => 51.4766277, lng => 0.0002212 },
location_type => "APPROXIMATE",
viewport => {
northeast => { lat => 51.4779740302915, lng => 0.00156183029150203 },
southwest => { lat => 51.4752760697085, lng => -0.00113613029150203 },
},
},
types => ["route"],
}
任何提示如何解决这个问题以及如何处理这样的结构?