Oy, there's a couple of places to start here...

1) "use strict;" and -w ... once i turned both of those things on, a bunch of little errors became obvious.

2) ARGV refers to your programs args, not your methods args, so you were getting lucky that "new" knew how to open $infile.

3) The difference between $foo and %foo...
This is sometimes a hard thing for people to grasp, but even though you refrence individual valuse of %foo as $foo{bar}, doesn't mean $foo is related.
I think your core problem is that you are never acctually creating the first hash -- even though your print statements make you think you do.
By declaring "my ($States,$other) =({}, {});" you are initializing $States as a hash ref, but when you then refer to "$States{$state}{$city} = $ary;" you aren't doing anything with your hash ref, you are now using the (previously undeclared) global hash %States ...
Your print statements misslead you because they are refering to %States as well!

(BTW: use strict & -w would have pointed those out to you, when I turned them on I got "Global symbol "%States" requires explicit package name at perlmonks.pl line XXX." which is what typed me off.)

take a look at the perlref man page for more info on how to use hash refs.


In reply to Re: Obj ref to %hoh by Anonymous Monk
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.