Q:

Perl hash returning value

I am a newbie in newbies for perl. I am trying to create a function which returns the value of the hash. The following piece of code simply returns the last index of the hash. I googled around and couldnt find what i need. Appreciate if anyone can tell me where I am going wrong.
I am expecting, if I pass "he_1", I should get a return back value of 1, etc.. but all I see is 9.
#!/usr/bin/perl

my %IndexMap = ();

my $MAX_V = 5;
my $MAX_T = 10;

sub InitIndexMap {
   foreach my $i (0..$MAX_V-1) {
      $IndexMap["he_".$i] = $i;
      print "he_".$i;
      print $IndexMap["he_".$i];
   }

    foreach my $i ($MAX_V..$MAX_T-1) {
      $IndexMap["un".$i] = $i;
      print "un".$i;
      print $IndexMap["un".$i];
    }
}

sub GetVal {
   my ($name) = @_;
   return $IndexMap[$name];
}

&InitIndexMap();
my ($index) = &Getval("he_4");
print $index;

A:

To read a hash, use curly braces, not brackets. Try this: 
sub InitIndexMap {
    foreach my $i (0..$MAX_V-1) {
        $IndexMap{ "he_" . $i } = $i;
        print "he_".$i;
        print $IndexMap{ "he_" . $i };
    }

    foreach my $i ($MAX_V..$MAX_T-1) {
        $IndexMap{ "un" . $i } = $i;
        print "un".$i;
        print $IndexMap{ "un" . $i };
    }
}

sub GetVal {
    my ( $name ) = @_;
    return $IndexMap{ $name };
}

You should add this to the top of the script: 
use strict;
use warnings;

The general rule to always turn those pragmas. They warnings and errors that that cause would have probably led you to the answer to your question. 

A:

You should access hashes with curly brackets like { and }.
$hash_name{$key} = $value;
In your example.
$IndexMap{"he_".$i} = $i;
You should consider doing some tutorials.
This is VERY BASIC knowledge in Perl.

