$key = "a";
$value = "hello";
%myhash = {} ;
push @{ myHash{$key} }, $hello;
print $myHash{$key}[0]."\n";
this script prints
"hello" but has following error message.
Reference found where even-sized list expected at ./test line 5.
can any one help me to fix this problem??
pludi
2
You're trying to assign a reference to a hash to a hash variable itself. Try it as
%myhash = ();
That, and the push line should rather be written as
push @{ $myHash{$key} }, $hello;
pludi
3
You're trying to assign a reference to a hash to a hash variable itself. Try it as
%myhash = ();
That, and the push line should rather be written as
push @{ $myHash{$key} }, $hello;
First off you don't have $hello set to anything, you have $value = "hello" -- not the same.
You should:
use strict;
use warnings;
and all would be reveled.
try:
use strict;
use warnings;
my $key = "a";
my $value = "hello";
my %myhash;
push @{ $myhash{$key} }, $value;
print "$myhash{$key}[0]\n"
also see: perldoc perldsc