Sorting exponential numbers

F

Fabrice Baro

I'm trying to sort a hash whose values are exponential numbers.

foreach my $file (sort values %{$files{$brh}}){
print "$file\n";
}
prints:
0
1e-101
1e-103
1e-104

I've tried storing those numbers under regular notation by using
sprintf to convert: but it's impractical and seems not exact:
here are some of the numbers I obtain:
0.00[...]00000999999999999999957534737399913078515638562734891876822570107876
0.00[...]00010000000000000000015234388133035855383875390450151974382791625208
where the numbers should be 0.00[...]0001. Obviously there are some
conversion issues.

I think one solution could be to write a custom compare block or
function, but I'd rather use a builtin feature of sort. However I
haven't found such a feature in the perl FAQ nor in the groups.
 
F

Fabrice Baro

[embarrassed]
Thanks Steven,
I had indeed read this, but I went over the fact my sort was a
"numerical" sort.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top