Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > hash key order different in perl 5.8?

Reply
Thread Tools

hash key order different in perl 5.8?

 
 
john_pataki@yahoo.com
Guest
Posts: n/a
 
      11-02-2004
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

 
Reply With Quote
 
 
 
 
Ala Qumsieh
Guest
Posts: n/a
 
      11-02-2004
wrote:

> 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
 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      11-02-2004


Ala Qumsieh wrote:
> wrote:
>
>> 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.


Yes, as of 5.8.0 there's a new algorithm.

See perl58delta.

http://search.cpan.org/~nwclark/perl...e_Enhancements

As of 5.8.1 the order is no longer consitant (to resist a particular
class of DoS attack).

See perl581delta.

http://search.cpan.org/~nwclark/perl..._Randomisation

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
Hash#keys, Hash#values order question Ronald Fischer Ruby 0 08-23-2007 09:34 AM
hash key to var name of value hash key value Une bévue Ruby 5 08-10-2006 04:05 PM
Hash#values and Hash#keys order Alex Fenton Ruby 1 04-15-2006 05:45 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57