in reply to Re: Permanently sort a hash
in thread Permanently sort a hash

Interesting, but it might not apply here. It returns the keys in lexical order (1,10,2,3,4,5,6,7,8,9) while the OP is sorting the keys in numerical order (1,2,3,4,5,6,7,8,9,10).

Replies are listed 'Best First'.
Re^3: Permanently sort a hash
by Arunbear (Prior) on Jun 04, 2009 at 17:01 UTC
    The default sort is lexical, but it can be made numeric:
    use strict; use warnings; use DB_File; $DB_BTREE->{'compare'} = sub { $_[0] <=> $_[1] }; tie my %foo, "DB_File", undef, undef, undef, $DB_BTREE; for (1 .. 10) { $foo{$_} = 'value' . $_; } while(my($k, $v) = each %foo) { print "$k -> $v\n"; }
      I read the docs entirely too fast. Thanks.