Since $ref is the exact same hash reference as $testhash{ "Tier 1" }, why does Perl spit out "Global symbol "$testhash" requires explicit package name" when I try to dereference the latter? I'm guessing Perl thinks that $testhash is a non-existent scalar, but I can't figure out why it isn't returning as the hash reference value and derefencing it. And to prove they are the same ref:#!/usr/bin/perl use strict; use warnings; my %testhash; $testhash{ "Tier 1" } = { "Tier 2" => "Tier 3" }; my $ref = $testhash{ "Tier 1" }; print $testhash{ "Tier 1" }, " is a reference.\n"; ###### Works Great ######## print %$ref, " is dereferenced.\n"; ###### Dies Horribly ###### print %$testhash{ "Tier 1" }, " is dereferenced.\n";
Thanks!print $ref, " is \$ref\n"; print $testhash{ "Tier 1" }, " is \$testhash\{ \"Tier 1\" \}\n"; ------------------------------ HASH(0x8dc2bdc) is $ref HASH(0x8dc2bdc) is $testhash{ "Tier 1" }
In reply to Nested Hash Dereferencing Syntax by jodv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |