bbrelin has asked for the wisdom of the Perl Monks concerning the following question:
Hello all,
I have a question regarding some perl code that i've written.
The code in question is looks like this:The problem that I have is that the map function doesn't actually return the list of key/value pairs. the output from Dumper is:#!/usr/bin/perl use strict; use Data::Dumper; my @dealers = ("Nissan","Toyota","Tesla","Chrysler","Ford","General Mo +tors"); my @cities = ("Belfast","Dublin","Cork","Derry","Tralee"); my %hashmap = (); my @car_city_dealer_aoa = ( [$cities[0],$dealers[1],$dealers[3],$dealers +[4]], [$cities[1],$dealers[2],$dealers[3],$dealers +[0]], [$cities[2],$dealers[0],$dealers[3]], [$cities[3],$dealers[1],$dealers[4],$dealers +[2]], [$cities[4],$dealers[2],$dealers[1],$dealers +[0],$dealers[5]]); # This is the goal #%Belfast_car_dealer_hash = ("Toyota"=> 1, # "Chrysler" => 1); # "Ford" => 1); %hashmap = map { my $arrayelem = $_; my $arraysize = scalar(@{$_}); $arrayelem->[$_] => 1 for (1..$arraysize-1) } $car_city_dealer_aoa[0]; print; print Dumper(%hashmap);
I suspect it's something simple and silly, but I can't figure out what the map command is returning here. It should be returning a list like: Toyota => 1, Nissan => 1 Can anyone seen anything obviously wrong?$VAR1 = ''; $VAR2 = undef;
Thanks,
Braun Brelin
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Having a problem creating a hash with the map function
by tobyink (Canon) on Nov 29, 2012 at 17:05 UTC | |
Re: Having a problem creating a hash with the map function
by choroba (Cardinal) on Nov 29, 2012 at 17:13 UTC | |
Re: Having a problem creating a hash with the map function
by Kenosis (Priest) on Nov 29, 2012 at 17:03 UTC | |
Re: Having a problem creating a hash with the map function
by space_monk (Chaplain) on Nov 29, 2012 at 17:05 UTC | |
Re: Having a problem creating a hash with the map function
by NetWallah (Canon) on Nov 29, 2012 at 21:47 UTC |
Back to
Seekers of Perl Wisdom