do not want to sort hash on key

Discussion in 'Perl Misc' started by niraj.kumar.ait@gmail.com, Aug 3, 2006.

  1. Guest

    My hash automatically sort the data on key. I do not want to sort data
    I just want to store the data in the way I store it.Is there any way

    TIA
    Niraj
    , Aug 3, 2006
    #1
    1. Advertising

  2. Guest

    wrote:
    > My hash automatically sort the data on key.


    No it doesn't. If you observe this behavior, it's pure coincidence (and
    it's probably a very small hash). Hashes are psuedo-random.

    > I just want to store the data in the way I store it.Is there any way


    Have you read the perl FAQ?

    perldoc -q order

    returns this relevant article:

    How can I make my hash remember the order I put elements into it?

    --
    David Filmer (http://DavidFilmer.com)
    , Aug 3, 2006
    #2
    1. Advertising

  3. Dr.Ruud Guest

    schreef:

    > My hash automatically sort the data on key.


    It doesn't.


    > I do not want to sort data
    > I just want to store the data in the way I store it.


    That's a FAQ:

    perldoc -q hash.*order


    > Is there any way


    Use an array.

    --
    Affijn, Ruud

    "Gewoon is een tijger."
    Dr.Ruud, Aug 3, 2006
    #3
  4. wrote:
    > My hash automatically sort the data on key.


    Hashes are mappings from text to scalar, they do not have any order or
    sequence. Claiming a hash is sorted is like saying the length() function
    (which maps from text to natural numbers) is sorted.

    What you might be seeing is that when printing the keys of the hash they
    happen to be printed in some sorted order. While this is not totally
    impossible the probability of this happening is extremely(!) low.

    > I do not want to sort data


    Hashes by definition don't. On the contrary, for better data management they
    deliberately pseudo-randomize the keys.

    > I just want to store the data in the way I store it.


    Then don't use a hash. Hashes don't have sequences or orders.

    > Is there any way


    Sure. Use an array.

    jue
    Jürgen Exner, Aug 3, 2006
    #4
    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. Angus Comber
    Replies:
    7
    Views:
    1,158
    Richard Heathfield
    Feb 5, 2004
  2. rp
    Replies:
    1
    Views:
    520
    red floyd
    Nov 10, 2011
  3. Une bévue
    Replies:
    5
    Views:
    149
    Une bévue
    Aug 10, 2006
  4. Mmcolli00 Mom
    Replies:
    5
    Views:
    138
    Mmcolli00 Mom
    Jan 12, 2009
  5. Antonio Quinonez
    Replies:
    2
    Views:
    168
    Antonio Quinonez
    Aug 14, 2003
Loading...

Share This Page