Hello all,

I have a question regarding some perl code that i've written.

The code in question is looks like this:
#!/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);
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:
$VAR1 = ''; $VAR2 = undef;
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?

Thanks,

Braun Brelin


In reply to Having a problem creating a hash with the map function by bbrelin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.