hash key order different in perl 5.8?

Discussion in 'Perl Misc' started by john_pataki@yahoo.com, Nov 2, 2004.

  1. Guest

    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
     
    , Nov 2, 2004
    #1
    1. Advertising

  2. Ala Qumsieh Guest

    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
     
    Ala Qumsieh, Nov 2, 2004
    #2
    1. Advertising

  3. 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-5.8.5/pod/perl58delta.pod#Performance_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-5.8.5/pod/perl581delta.pod#Hash_Randomisation
     
    Brian McCauley, Nov 2, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rp
    Replies:
    1
    Views:
    537
    red floyd
    Nov 10, 2011
  2. Une bévue
    Replies:
    5
    Views:
    153
    Une bévue
    Aug 10, 2006
  3. Steve D
    Replies:
    0
    Views:
    132
    Steve D
    Aug 22, 2003
  4. filippo
    Replies:
    13
    Views:
    204
    John Bokma
    Jun 16, 2006
  5. Krishna Chaitanya

    Hash key iteration order

    Krishna Chaitanya, Dec 3, 2010, in forum: Perl Misc
    Replies:
    2
    Views:
    183
Loading...

Share This Page