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
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).print "DEBUGGING: \n", join ",", keys %$weather;
The solution for this particular problem is to make one simple change:
becomes$States{$state}{$city}
$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!
In reply to Re: Obj ref to %hoh
by ChemBoy
in thread Obj ref to %hoh
by Robertn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |