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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.