Perl Monk, Perl Meditation | |
PerlMonks |
Re: Fail to update an array in HoAoAby Fang (Pilgrim) |
on Jul 20, 2005 at 07:43 UTC ( [id://476397]=note: print w/replies, xml ) | Need Help?? |
There are multiple logical design errors in the flow of your program. One of them is that you assign an arrayref to $hoa{$key} while you want it to be an arrayref itself, so you have to push your data in that array like push @{hoa{$key}}, [ @aoa ]. This assignment is also misplaced, as it will push an empty arrayref in case the line from <DATA> doesn't match any of the pattern you mentionned (/^\s+/ won't match an empty line by the way, /^$/ will).
Here's some code that will produce what you want. You may look at that solution (among others, as always) directly, or try and correct your code a bit by yourself first.
Update: updated explanations a bit, small updates to the code.
In Section
Seekers of Perl Wisdom
|
|