Syntactic Confectionery Delight | |
PerlMonks |
Re: Lining up many hash valuesby robartes (Priest) |
on May 02, 2003 at 06:44 UTC ( [id://254919]=note: print w/replies, xml ) | Need Help?? |
Dotproducts and angles bring back scary memories from my uni days, so I'm not going to go there :)
pzbagel was right in saying that the ordering of hashes in Perl is not deterministic: nothing guarantees that you always get stuff out in the same order as you put them in (in fact, given the nature of the hashing algorithm, you are virtually guaranteed that you get them out in a different order than they went in). If you want to guarantee a consistent order (though not necessarily the initial order), use sort on the list returned by keys %hash. However, this seems to be more of a case for arrays than hashes. As you say, all your hashes have identical keys, both in number and name. If you want to associate some kind of descriptive name to the array elements, keep a seperate array of names. Something like this: Or even use an AoA to store your actual data:
CU
In Section
Seekers of Perl Wisdom
|
|