in reply to [untitled node, ID 254219]
First you can use the hash reference inside of the scalar very similar to a normal hash, just use $$hash{foo}:
my $hash_ref = { a => 1 , b => 2 , } ; print "$$hash_ref{a}\n" ; print "$$hash_ref{b}\n" ;
But if you really want to use $hash{foo} directly, without make a copy, use this code:
But note that %hash is declared inside *hash, with local() to simulate the my %hash! And any other variable or handle with the name hash will be overwrited. In other words, local() works for: $hash, @hash, %hash, hashmy $hash_ref = { a => 1 , b => 2 , } ; local(*hash) ; *hash = $hash_ref ; print "$hash{a}\n" ; print "$hash{b}\n" ;
Graciliano M. P.
"The creativity is the expression of the liberty".
|
|---|