in reply to Fail to update an array in HoAoA
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:my @KEY = split (/[\s:]/,$_);
For data like this set, you could completely replace this split with a regular expression, avoiding the use of the intermediate arrays.my @KEY = split( /: /, $_ );
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.
-- Foxcub
#include www.liquidfusion.org.uk
|
|---|