do not want to sort hash on key

  • Thread starter niraj.kumar.ait
  • Start date
N

niraj.kumar.ait

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
 
U

usenet

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?
 
J

Jürgen Exner

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
 

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,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top