I don't see offhand what would be wrong with AppleFritter's code, but here's some code closer to your OP, at least as regards sorting. Critically, IMHO, this code includes example data. Can you say where the 'disorder' creeps in? (In particular, since the sort comparison in AppleFritter's code is lexic versus numeric in the original, how can it be the same disorder?)
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le
"my %funcs = qw(1 a 2 aa 3 aaa 4 z 5 zz 6 b 7 bb);
dd \%funcs;
;;
my @sorted_keys = sort { $funcs{$a} cmp $funcs{$b} } keys %funcs;
dd \@sorted_keys;
;;
my @sorted_vals = @funcs{@sorted_keys};
dd \@sorted_vals;
;;
print qq{'$_' -> '$funcs{$_}'} for @sorted_keys;
"
{ 1 => "a", 2 => "aa", 3 => "aaa", 4 => "z", 5 => "zz", 6 => "b", 7 =>
+ "bb" }
[1, 2, 3, 6, 7, 4, 5]
["a", "aa", "aaa", "b", "bb", "z", "zz"]
'1' -> 'a'
'2' -> 'aa'
'3' -> 'aaa'
'6' -> 'b'
'7' -> 'bb'
'4' -> 'z'
'5' -> 'zz'
|