J33nn
J33nn

Reputation: 3234

Dereference hash list in Perl

I'm having problem with deferencing hash table. Here is Dumper result of my variable:

$VAR1 = \{
    'key' => 'value1',
    'key2' => 'value2',
    'key3' => 'value3',
};

I've tried to access elements like this:

echo $table->{'key'}; 

But it keeps returning me error:

Not a HASH reference at somescript.pl line 10.

Upvotes: 2

Views: 134

Answers (2)

bhb
bhb

Reputation: 2561

Double referencing can be done by $$variable_name. For more info try this - http://perldoc.perl.org/perlref.html

Upvotes: 1

cyberz
cyberz

Reputation: 923

{ ... } returns already a reference to an hash, so \{ ... } returns a reference to a reference to an hash (double pointer).

Said so you could then deference it using ${$table}->{'key'}.

Upvotes: 6

Related Questions