in reply to Sorting Puzzle
Your "numbers" don't appear to be variable-width so just sort w/o specifying any comparison routine and you'll get the desired order:
foreach $j ( sort keys %test ) {
Others have pointed out that your numbers are too big for accurate numeric comparisons in Perl. The notes about avoiding the quotes or hash keys being strings and having to use "0+" to force numeric interpretation make no sense to me, however. $a <=> $b already forces $a and $b to be interpretted as numbers, always.
Your numbers require about 91 bits and Perl usually uses about 53 bits of mantissa for floating point numbers so numeric comparison on these values end up comparing truncated values like 2007030110300020000000000000 instead.
- tye
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting Puzzle (just sort)
by imp (Priest) on Feb 20, 2007 at 22:26 UTC | |
by tye (Sage) on Feb 20, 2007 at 22:31 UTC | |
|
Re^2: Sorting Puzzle (just sort)
by jdporter (Paladin) on Feb 20, 2007 at 22:51 UTC | |
by imp (Priest) on Feb 20, 2007 at 22:59 UTC | |
| |
by ysth (Canon) on Feb 20, 2007 at 23:34 UTC | |
by jdporter (Paladin) on Feb 21, 2007 at 01:56 UTC | |
by ysth (Canon) on Feb 21, 2007 at 02:52 UTC |