Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Hash of arrays of hashesby NetWallah (Canon) |
on Apr 14, 2013 at 18:40 UTC ( [id://1028638]=note: print w/replies, xml ) | Need Help?? |
Change your data structure to be closer to how your data actually looks. I.E. instead of squeezing a hashref into an array, make it a real hashref: Replace "[]" with "{}" in your data; You can always "SORT" it later, if necessary. A simple sort is used above. In real life, your sort sub may be complicated if you want to preserve true numeric order in the port. One alternative is to add an ORDER field within the port info, and manually increment it. That field can subsequently be used as a sort key. There are also modules that provide (tied) ordered-key hashes. (eg: Data::XHash).
Update: If you really wanted to keep the current data structure (in case it came from outside your control), you will need to process every other element : i.e. skip the hashref, process only the "key" which is a scalar.
"I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
In Section
Seekers of Perl Wisdom
|
|