in reply to Dereferencing references
$g{\%h} = 1;
does not actually store the reference to the %h hash in any way, all it does is add an element to the %g hash with 1 as the value and the string representation of the %h hash ("HASH(0x90fcc70)") as the key. If you really want to use this string representation as the key (not a good idea IMO) you'd do
use strict; my %h = ("foo" => 1, "bar" => 2); my %g = (); $g{\%h} = \%h; my @k = keys %g; my $hashref = $k[0]; my %tmp = %{$g{$hashref}}; print $tmp{"foo"}
I think you should use something more useful as the hash key, or, if you just want to store hash references in a data structure without meaningful keys, use an array instead:
use strict; my %h = ("foo" => 1, "bar" => 2); push (my @g,\%h); my $hashref = $g[0]; print $hashref->{foo};
Also, consider using more descriptive variable names (unless this is just an example and not your actual code).
|
|---|