You can use
grep to pick a member from an array. You can use
map to turn the list of hash refs to a list of values stored inside of them.
#!/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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.