Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have a hash and one of the key-vaules are $args{"my_key"}=["name1","name2"]
When I try to deference it I have to do this
$temp=$args{"my_key"};
@my_array=@$temp;
Why does not it work if I directly dereference it like below
@my_array=@$args{"my_key"};
#!/usr/bin/perl %my_hash=('k1',"123","k2",["Bach","Bachi"]); @my_aray=@$my_hash{"k2"}; print "First try \n"; print @my_aray; print"Second try \n"; $temp=$my_hash{"k2"}; @my_aray=@$temp; print @my_aray; print "\n";
Output is
First try
Second try
BachBachi
Thanks in Advance!!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: dereferencing an array store in hash
by toolic (Bishop) on Mar 15, 2011 at 19:08 UTC | |
|
Re: dereferncing a an array store in hash
by wind (Priest) on Mar 15, 2011 at 19:09 UTC |