how to efficiently sort hash without using keys()



Hi beginners@xxxxxxxx,

anyone has better idea how to sort hash by key without using keys()
function? (I can't use it, it resets iterator...).

my bruteforce looks:

use strict;
use warnings;

my %hash = ( 1 => 'one',
2 => 'two',
3 => 'three'
);

my @array = ();
while (my ($key, $value) = each(%hash)) {
push @array, $key;
}
@array = sort @array;

but I think there should be better way. Anyone?
I mean, snippet should do something like:

for my $key (sort {$a <=> $b} keys %hash) {
#do something $key
}

thanks.

--

--. ,-- ,- ICQ: 7552083 \|||/ `//EB: www.2ge.us
,--' | - |-- IRC: [2ge] (. .) ,\\SN: 2ge!2ge_us
`====+==+=+===~ ~=============-o00-(_)-00o-================~
Hard disk parking: .10/mb for the 1st 2 hrs; all day=$25




.