hash key order different in perl 5.8?

J

john_pataki

I just updated my perl version to 5.8 from 5.6.1 and with no code
change in the area of my list creation.... but I get a different order
now...

Here is the code I believe to be in question:


my @details = ((basename($fi)),$na,$nu,$ve,$ls,$st);
push @{$LIB_ITEMS{$pr}{$li}{$asm++}},@details;

.... later in my code...

foreach my $asm (keys %{$LIB_ITEMS{$prj}{$lib}}) {
....
}


I know that you cannot rely on a specific order from keys stored in a
hash -- however -- I did get a consistant order one way in 5.6.1 now I
get a consistant yet different order now in 5.8

It appeared that it was alpabetical (for $asm) in 5.6.1. and now
reverse alphabetical in 5.8

? anyone else notice this ?

I can just use a sort command with my keys -- just thought it was odd
that it was different.

John
 
A

Ala Qumsieh

I know that you cannot rely on a specific order from keys stored in a
hash -- however -- I did get a consistant order one way in 5.6.1 now I
get a consistant yet different order now in 5.8
Correct.

It appeared that it was alpabetical (for $asm) in 5.6.1. and now
reverse alphabetical in 5.8

? anyone else notice this ?
Yes.

I can just use a sort command with my keys -- just thought it was odd
that it was different.

No it's not really odd, since it is documented. From 'perldoc -f keys':

The actual random order is subject to
change in future versions of perl, but it is
guaranteed to be the same order as either the
"values" or "each" function produces ...

It is probably the side-effect of some internal optimization.

--Ala
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top