in reply to sorting scientific numbers
Chances are good that by virtue of how the numeric data is getting into your script, Perl is seeing '1e-13' as a string, not a number. You can see this happening here:
perl -e "print q/2e+11/, $/; print 2e+11, $/;"
You can coerce it back to a number by treating it like one. One way is by adding zero to it:
perl -e "print q/2e+11/ + 0, $/;"
And here is that theory applied to an example that may more closely resemble your problem code.
my @numbers; while( my $num = <DATA> ) { chomp $num; push @numbers, $num + 0; } print "$_\n" for sort { $a <=> $b } @numbers; __DATA__ 1e-13 2e-18 1e-11
I hope this is on the right track. ;)
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sorting scientific numbers
by kaif (Friar) on Jun 08, 2005 at 07:57 UTC | |
|
Re^2: sorting scientific numbers
by tlm (Prior) on Jun 08, 2005 at 12:31 UTC |