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
In reply to Having a problem creating a hash with the map function by bbrelin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |