in reply to Nested hashes, non-unique names

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.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Nested hashes, non-unique names
by kthelen (Initiate) on Mar 17, 2014 at 15:12 UTC
    Perfect! Thanks for the help.
Re^2: Nested hashes, non-unique names
by kthelen (Initiate) on Mar 19, 2014 at 14:14 UTC
    One other stupid question...

    I realized within the past day that the layout key sometimes changes. It was "k-p12h-n13-1" when I first posted, but since then they changed it to "k-p12h-n14-1".

    Having looked at some old data, it seems as though the one part which never changes is "k-p12h-n".

    I've been trying to modify the grep above to match that, but am having no success. Have tried umpteen different ways so far, but none have worked. (I can change the operator from "eq" to "=~" without breaking it, which seems to be a step in the right direction. But if the pattern isn't contained within single quotes it breaks, and I can't seem to use a regex within single quotes, nor get it to match a partial string within single quotes.)

    grep /k-p12h-n/ =~ $_->{'layout-key'}

    was the first thing that came to my mind, but that's clearly not correct. I know I'm missing something here, I'm just not seeing what...

      The string to match goes on the left, the pattern on the right:
      grep $_->{'layout-key'} =~ /k-p12h-n/,
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        Simple as that. Thanks again!