in reply to Determining hash order for sorting array
The actual random order is subject to change in future versions of perl, but it is guaranteed to be the same order as either the "values" or "each" function produces (given that the hash has not been modified).So in short you cannot depend on the keys, values, or each functions to provide results in a pre-determined order. There are ways around this .. I believe (haven't actually used it personally) that
my %h = ( ... ); foreach my $k ( sort { lc $a cmp lc $b } keys %h ){ # get keys sorte +d by lowercase of key ... } foreach my $k ( sort { lc $h{$a} cmp lc $h{$b} } keys %h ){ $ get key +s sorted by lowercase of value ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Determining hash order for sorting array
by halley (Prior) on Aug 21, 2005 at 18:02 UTC | |
|
Re^2: Determining hash order for sorting array
by bart (Canon) on Aug 21, 2005 at 20:17 UTC |