Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > do not want to sort hash on key

Reply
Thread Tools

do not want to sort hash on key

 
 
niraj.kumar.ait@gmail.com
Guest
Posts: n/a
 
      08-03-2006
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

 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      08-03-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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)

 
Reply With Quote
 
 
 
 
Dr.Ruud
Guest
Posts: n/a
 
      08-03-2006
(E-Mail Removed) 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."


 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      08-03-2006
(E-Mail Removed) 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



 
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
sort hash, hash key and val off by one, see attached Mmcolli00 Mom Ruby 5 01-12-2009 02:06 PM
hash key to var name of value hash key value Une bévue Ruby 5 08-10-2006 04:05 PM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM
sort multi-key hash by value and print out with key value pairs Antonio Quinonez Perl Misc 2 08-14-2003 10:56 PM



Advertisments