This seems a little homeworky to me, so I'm not going to just write some code for you. I'll point out a few areas I think you should look at to get a little closer to where you need to be.

Take a closer look at the line

my @KEY = split (/[\s:]/,$_);
If you're trying to split the line on ': ' (colon space), I don't think you want to be using a character class: simply the literal ': ' will do:
my @KEY = split( /: /, $_ );
For data like this set, you could completely replace this split with a regular expression, avoiding the use of the intermediate arrays.

Secondly, think about your @aoa array. As you have it at the minute, it's being redefined each time the while loop iterates. Is that what you need to happen?

Finally, think about your assignment to the %hoa. It's going to the array you have so far to the hash each time the loop iterates - which doesn't seem healthy to me.

I'd consider making use of a second loop, something like this:

for each data line { grab the key loop assign data rows to the array of arrays until there's no more data assign array of arrays to hash }

Using an inner loop in this way will allow you to read the key separately to reading the data, meaning that you can build a complete array of arrays before assigning it to the hash of arrays. This also helps to make your code more readable (in my opinion), and hence more maintainable.

Hope that helps you a little.


In reply to Re: Fail to update an array in HoAoA by Tanalis
in thread Fail to update an array in HoAoA by Anonymous Monk

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.