Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: More Sorted Business with Hashes

by IlyaM (Parson)
on Dec 22, 2001 at 05:56 UTC ( [id://133931] : note . print w/replies, xml ) Need Help??


in reply to Re: More Sorted Business with Hashes
in thread More Sorted Business with Hashes

Hashes are inherently non-ordered

It is not correct. Hash can be made ordered. It is in perl FAQ: How can I always keep my hash sorted?

--
Ilya Martynov (http://martynov.org/)

Replies are listed 'Best First'.
Re: Re: Re: More Sorted Business with Hashes
by dws (Chancellor) on Dec 22, 2001 at 06:07 UTC
    Sure, a tied hash can be kept ordered, by using an array, or some heavier-weight data structure, underneath it.

Re (tilly) 3: More Sorted Business with Hashes
by tilly (Archbishop) on Jan 03, 2002 at 05:50 UTC
    The FAQ notwithstanding, the original statement is correct. Hash lookup algorithms produce fundamentally unordered results. Perl's hashes implement a concept properly called associative arrays. They are called hashes because that is how they work under the hood.

    Therefore native Perl hashes are not obviously ordered, and anything you run across in any language called a hash should be assumed to likewise be not obviously ordered.