jodv has asked for the wisdom of the Perl Monks concerning the following question:
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" }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Nested Hash Dereferencing Syntax
by ikegami (Patriarch) on Feb 24, 2009 at 17:27 UTC | |
by jodv (Initiate) on Feb 24, 2009 at 17:31 UTC | |
by tilly (Archbishop) on Feb 24, 2009 at 18:19 UTC | |
by ikegami (Patriarch) on Feb 24, 2009 at 18:31 UTC | |
by tilly (Archbishop) on Feb 24, 2009 at 21:21 UTC | |
by chromatic (Archbishop) on Feb 24, 2009 at 19:03 UTC | |
by ikegami (Patriarch) on Feb 24, 2009 at 17:38 UTC | |
by Bloodnok (Vicar) on Feb 24, 2009 at 18:11 UTC | |
by tilly (Archbishop) on Feb 24, 2009 at 18:24 UTC | |
|
Re: Nested Hash Dereferencing Syntax
by planetscape (Chancellor) on Feb 24, 2009 at 18:52 UTC | |
|
Re: Nested Hash Dereferencing Syntax
by toolic (Bishop) on Feb 24, 2009 at 17:36 UTC |