CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
how do i now/change the order of a hash

 



rj_one
Deleted

Nov 23, 2000, 11:17 PM

Post #1 of 2 (138 views)
how do i now/change the order of a hash Can't Post

Problem:
I want to put a special key&value to the first position of the existing hash...

Does anybody know how the order of hash is
specified?

thx


perlplexer
Deleted

Nov 24, 2000, 5:43 AM

Post #2 of 2 (138 views)
Re: how do i now/change the order of a hash [In reply to] Can't Post

Hashes are NOT ordered; therefore, there is no such thing as 'the first' position.

You can use sort() to order keys depending on what your needs are (<=> or cmp).
for (sort keys %hash){print $hash{$_}}

That, however, provides you with a sorted
_copy_ of keys. It does not actualy sort
the hash itself.
You can imitate ordered hash with two arrays
and a real hash. It is not hard to do but it
is not trivial either.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives