I am trying to write a program that searches through a directory, and finds files with names that look like this:
xx_000000
where the 'xx' is a two-letter city abbreviation and the number is just a six digit ID number. What I then want to do is open the file, and store all the data in a array-of-a-hash-of-a-hash - I think. Honestly, I have a very difficult time with these types of structures. Here is what I am doing:
my %city_data = (); my ($city, $id) = split(/_/,$filename); open(THIS,"$filename") or die; my @tmp = <THIS>; close(THIS); push @{ $city_data{$city}{$id} }, @tmp;
Now, it seems like this should work correctly, but I can't tell if it does. First of all, is my approach correct? Secondly, if so, how would I print out everything that is in the @{$city_data{$city}{$id}} array? I know that this may be a simple question for most, and I have read everything I could find on PM and elsewhere about this subject, but I am still lost. Could someone please try to explain this to me, in detail if you wouldn't mind, so that hopefully the next time I have a problem like this I am not as lost as I am now? Thanks so much to all the gracious helpers out there (and to all who aren't so gracious, thanks anyway :-).

R.Joseph

In reply to Confused about complex data structures. by r.joseph

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.