Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Fail to update an array in HoAoAby Tanalis (Curate) |
on Jul 20, 2005 at 07:52 UTC ( [id://476402]=note: print w/replies, xml ) | Need Help?? |
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 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: 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:
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. -- Foxcub
In Section
Seekers of Perl Wisdom
|
|