Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Lining up many hash values

by robartes (Priest)
on May 02, 2003 at 06:44 UTC ( [id://254919]=note: print w/replies, xml ) Need Help??


in reply to Lining up many hash values

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:

my @names=qw/value1 value2 value3/; my @array1=(1, 2, 3); my @array2=(4, 5, 6);
Or even use an AoA to store your actual data:
my @AoA; push @AoA, [ 1,2,3 ]; push @AoA, [ 4,5,6 ]; #Then use them as such: $AoA[0][0]; # 1st element of first array $AoA[1][0]; # 1st element of second array

CU
Robartes-

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://254919]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-19 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found