PerlSufi has asked for the wisdom of the Perl Monks concerning the following question:

UPDATE: RESOLVED
Hello Monks,
I am trying to map the results of a function from a module, Locale::SubCountry for use in template variables later. It is desired that the code and name of the subcountry be separate lists. However, when I try to map them as follows I get 'unkown' as the value for the 'name' key:
use strict; use warnings; use Data::Dumper; use Locale::SubCountry; my $country = new Locale::SubCountry('United States'); my @states = $country->all_codes; my @list; my %state_hash = $country->code_full_name_hash; our $subcountry = do { @list = map { { code => uc($_), name => $country->full_name }} + @states; }; print Dumper(\@list);
Any insight into how I can get the full name mapped out properly would be greatly appreciated

Replies are listed 'Best First'.
Re: Mapping results of a Function
by perlfan (Parson) on Jun 17, 2014 at 15:07 UTC
    FTFY, you need to pass $_ to full_name so it knows what subcountry you want to look up.

    use strict; use warnings; use Data::Dumper; use Locale::SubCountry; my $country = new Locale::SubCountry('United States'); my @states = $country->all_codes; my @list; my %state_hash = $country->code_full_name_hash; our $subcountry = do { @list = map { { code => uc($_), name => $country->full_name($_ +) }} + @states; }; print Dumper(\@list);