You're very close--just one problem is screwing you up. You create a hash reference called $States, bless it and return it as your new object. Unfortunately, you do your initialization code on a hash called %States, which is sadly completely unrelated to $States. If you add a line like

print "DEBUGGING: \n", join ",", keys %$weather;
after your object creation code, you'll see that your object has no data in it. (Alternatively, take a good look at it using the Perl Debugger, which makes it very easy to view data structures and see if they contain what you think they should).

The solution for this particular problem is to make one simple change:

$States{$state}{$city}
becomes
$States->{$state}{$city}

You will then have to debug your debugging code, as well, but I can see from the rest of your code that you already know what the correct syntax for reading from a hash reference is, so I won't bother you with that.

What I will bother you with is what could have prevented this problem in the first place: use strict;. Had you tried compiling Rainfall.pm under strict, you would have gotten the following error message from line 21 (or thereabouts):
Global symbol "States" requires explicit package name Which would have told you, in turn, that the "States" in that line was not the "States" you thought you were working with. And saved you all sorts of debugging time, too. :-)

Welcome to the Monastery, and good luck!



If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders


In reply to Re: Obj ref to %hoh by ChemBoy
in thread Obj ref to %hoh by Robertn

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.