in reply to Permanently sort a hash

Try DB_File (from the FAQ mentioned by kennethk), e.g.
use strict; use warnings; use DB_File; tie my %foo, "DB_File", undef, undef, undef, $DB_BTREE; %foo = (1 => 'value1',2 => 'value2',3 => 'value3'); while(my($k, $v) = each %foo) { print "$k -> $v\n"; }

Replies are listed 'Best First'.
Re^2: Permanently sort a hash
by ikegami (Patriarch) on Jun 04, 2009 at 16:12 UTC
    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).
      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.