abhy has asked for the wisdom of the Perl Monks concerning the following question:
I am confused with the syntax used to dereference a hash, when the reference is obtained from a hash(or array) and when there is a direct reference.
Consider this code snippet:
my $ref = {"one" => "1"}; my %hash = ("ref" => $ref); my @array = ($ref); print "Array:", $array[0]{"one"}, "\n"; print "Hash:", $hash{"ref"}{"one"}, "\n"; print "Ref:", $$ref{"one"}, "\n";
When the reference is taken from a hash or array it is preceded by just a single sigil that of the array or hash, but when it is a direct reference it is preceded by a double sigil.
In the above snippet is it not $ref that I get when I do $array[0]? Since I have $ref with me, should I not use another sigil to reference the value stored in the hash as is done with a direct reference?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash dereferencing
by targetsmart (Curate) on Mar 05, 2009 at 06:35 UTC | |
|
Re: Hash dereferencing
by chromatic (Archbishop) on Mar 05, 2009 at 06:38 UTC | |
|
Re: Hash dereferencing
by abhy (Novice) on Mar 06, 2009 at 06:51 UTC |