in reply to Nested hashes, non-unique names
#!/usr/bin/perl use strict; use LWP; use XML::Simple; use Data::Dumper; my $var_lat = "45.96968"; my $var_lon = "-93.33434899999997"; my $ua = LWP::UserAgent->new; my $forecast_xml = $ua->request(HTTP::Request->new(GET => "http://fore +cast.weather.gov/MapClick.php?lat=$var_lat&lon=$var_lon&unit=0&lg=eng +lish&FcstType=dwml")); my $forecast_arr = XMLin($forecast_xml->content); my ($item) = grep 'k-p12h-n13-1' eq $_->{'layout-key'}, @{ $forecast_arr->{data}[0]{'time-layout'} }; my @names = map $_->{'period-name'}, @{ $item->{'start-valid-time'} }; print "@names\n";
Update: The structure you are dealing with is not a hash of hashes, but an array of hashes (that's why you were able to iterate for over it). VAR1 is not a key, it is just what Data::Dumper adds to the output.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Nested hashes, non-unique names
by kthelen (Initiate) on Mar 17, 2014 at 15:12 UTC | |
|
Re^2: Nested hashes, non-unique names
by kthelen (Initiate) on Mar 19, 2014 at 14:14 UTC | |
by choroba (Cardinal) on Mar 19, 2014 at 14:24 UTC | |
by kthelen (Initiate) on Mar 19, 2014 at 14:38 UTC |