A hash consists of key/value pairs, just one value per key. Your first statement assigns the value "4" to the key "tree". Your second statement replaces the value "4" with a reference to an anonymous sub-hash containing the key/value pair of "apple" and "6" and in the third statement you replace "6" with a sub-sub-hash containing "red" and "9" as key and value. At each stage you are replacing the previous value with reference to a new anonymous hash which is why your first-level values have disappeared. The fourth statement adds a second key/value pair of "fuji" and "4" to the sub-sub-hash.

I hope this explains where you are going wrong. Perhaps if you could describe what data structure you are trying to build we could give further advice. You will find the Data::Dumper module useful when trying to visualise the data structures you have created.

Cheers,

JohnGG


In reply to Re: (another) HoH question by johngg
in thread (another) HoH question by zuma53

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.