Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Are keys always of type string? If not, why is 10 printed after 1 instead of 2? How do I sort as: 1,2,3...10. Thanks.my %statistics = ( 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0 ); foreach my $statistic (sort keys %statistics) { print $statistic ." ".$statistics{$statistic}. "\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sorting integer value hash keys
by CountZero (Bishop) on Dec 25, 2009 at 16:38 UTC | |
Re: Sorting integer value hash keys
by gube (Parson) on Dec 25, 2009 at 18:08 UTC | |
by JadeNB (Chaplain) on Dec 25, 2009 at 18:53 UTC | |
by ikegami (Patriarch) on Dec 25, 2009 at 19:25 UTC | |
by JadeNB (Chaplain) on Dec 25, 2009 at 19:41 UTC | |
by ikegami (Patriarch) on Dec 25, 2009 at 20:01 UTC |
Back to
Seekers of Perl Wisdom