Your problem is almost fixed, except that you called the second printit() before you assigned $reports to the new hash table. So your second printit() is still printing the old hash table.

Change your code to:
# save the file $reports = \%reports ; printit();
And you will print your second hash table correctly.

If $reports{$year} and $reports->{$year} are different variables, and $reports->{$year} is a hash reference, then what is $reports{$year}?

This is because $reports is a reference that points to the %reports hash table. The %reports hash table gets created after your first printit(). In your original code, in your first printit(), you tried to refer to the loaded $reports to get your year values, and then refer to undefined %reports with $reports{$year}, which has not yet been initialized. Because you haven't used strict at the beginning of your code, Perl happily created the undefined variable for you.

Cheers. Roger.

In reply to Re: Re: Re: Storable with hash of hashes (reference problem?) by Roger
in thread Storable with hash of hashes (reference problem?) by ManyCrows

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.