in reply to how do i sort hash by key numerically

This would do the trick:
#!/usr/bin/perl -w %hash=( 89=>3, 45=>2, 1 =>5, 40=>3); foreach (sort { $a <=> $b } keys(%hash) ) { print "key: $_ value: $hash{$_}\n" }
Jouke Visser, Perl 'Adept'

Replies are listed 'Best First'.
Re: Answer: how do i sort hash by key numerically
by Tyke (Pilgrim) on Mar 07, 2001 at 16:35 UTC
    Are you sure that this doesn't sort typographically rather than numerically. I think the {$a<=>$b} block cited by arhuman is necessary here.
    -- I knock my pate and fancy wit will come Knock as I please, there's no one at home a pontiff paraphrased