-
Notifications
You must be signed in to change notification settings - Fork 578
each() function used with Associative array gives unordered incorrect output. #4873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
From [email protected]Hi. SOS.... Arvind Tiwari |
From [email protected]Created by Administrator@localhost%array = ( "100", "Green", "200", "Orange"); while (($key, $value) = each(%array)) { Acc. to the functionality of above code, each() function used on associative array, This program should print the following: 100 = Green But on running it on my machine, it returns: 200 = Orange On adding more key, value pairs it gives different results which I cannot find a pattern for. Regards. Perl Info
|
From [Unknown Contact. See original ticket]On Jan 19, Arvind Tiwari said:
Hashes are not kept in the order that you create them in. This is an If you need a sorted hash in Perl, you can use the Tie::IxHash module, -- |
From [Unknown Contact. See original ticket]Thus spake Arvind Tiwari (arvindt@tis.co.in): You don't seem to have a bug.
This is not a bug. The docs say each() returns its results in
The pattern is in the hashing code.
The first case is working, and the machine which seems to be If you really need your values sorted, perhaps you should do my @key = sort ( keys %hash ); It takes a little more memory, but it's how I'd do it. For future programming questions, please see Usenet groups, the Chris Stith -- |
From @schwernUser had a misconception that hashes are ordered. -- Michael G. Schwern <schwern@pobox.com> http://www.pobox.com/~schwern/ |
Migrated from rt.perl.org#8283 (status was 'resolved')
Searchable as RT8283$
The text was updated successfully, but these errors were encountered: