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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.