FreeKB - Perl Hash (multidimensional hash)
Perl - Hash (multidimensional hash)

Let's say you want to create a hash that has two (or more) keys, like this. In this example, name_key is below employee_key.

'employee_key' {
                 'name_key' => 'John Doe',


Create the multidimensional keys and value.

my %hash = ( 'employee_key' => { 'name_key' => 'John Doe' } );


Or like this.

my $hash{employee_key}->{name_key} = "John Doe";


Dumper can be used to print the hash.

print Dumper \%hash;


Which will produce the following.

$VAR1 = {
          'employee_key' => {
                              'name_key' => 'Jane Doe'


Print name_key.

print $hash{employee_key}->{name_key};


Which will produce the following.

John Doe


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 7c00b in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |