The idea strike to my mind when I encounter this
use Data::Dumper; $hash{keya} ; $hash{keyb} ; $hash{keyc} ; $hash{keya}{1} = "fooA"; $hash{keya}{2} = "barA"; $hash{keyb}{1} = "fooB"; $hash{keyb}{2} = "barB"; $hash{keyc}{1} = "fooC"; $hash{keyc}{2} = "barC"; print Dumper (\%hash); __output__ $VAR1 = { 'keya' => { '1' => 'fooA', '2' => 'barA' }, 'keyb' => { '1' => 'fooB', '2' => 'barB' }, 'keyc' => { '1' => 'fooC', '2' => 'barC' } };
Let this is case 1. I assigned 2 values to each key (keya, keyb, keyc). Note that $hash{keya}{1} also a hash itself, so I supposed $hash{keya} is pointed to an array of pointers, which in turn pointed to $hash{keya}{1} and $hash{keyb}{2} respectively. And $hash{keya}{1} pointed to value "fooA" ultimately.
However, in case 2, which I initialize hash like this:
use Data::Dumper; $hash{keya} = ""; $hash{keyb} = ""; $hash{keyc} = ""; $hash{keya}{1} = "fooA"; $hash{keya}{2} = "barA"; $hash{keyb}{1} = "fooB"; $hash{keyb}{2} = "barB"; $hash{keyc}{1} = "fooC"; $hash{keyc}{2} = "barC"; print Dumper (\%hash); __output__ $VAR1 = { 'keya' => '', 'keyb' => '', 'keyc' => '' };
As you notice $hash (keya, keyb, keyc) is as its initialize value, not pointed to each {1} and {2} repectively. $hash{keya}{1} is still exist if you print it out. But $hash{keya} cannot access $hash{keya}{1} anymore.
Hence I deduced that hash is an array of pointer. ^_^, up to here, I have no concrete evidence or proof, that why I put up my query here to ask for advice. Hope can share with you guys.
Regards,
donno20 ^_^

In reply to Re: Re: Hash and Array by donno20
in thread Hash and Array by donno20

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.