Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: sorting an array with decimal points

by salva (Abbot)
on Jan 15, 2018 at 08:04 UTC ( #1207264=note: print w/replies, xml ) Need Help??


in reply to Re: sorting an array with decimal points (updated)
in thread sorting an array with decimal points

Better yet, just use the Sort::Naturally module from CPAN

Sort::Naturally does not handle numbers with decimals correctly. For instance, nsort '1.10', '1.31', '1.4' returns 1.4 1.10 1.31.

But you can use Sort::Key::Natural instead which provides a set of functions for sorting strings embedding numbers with decimals:

use Sort::Key::Natural qw(natwfsort); my @sorted = natwfsort @array;

Update: Though, taking into account that the data in the OP says Patch_, maybe those numbers are actually version numbers and then the part after the decimal dot may be better sorted as an independent integer, which is what a regular natural sort does...

Replies are listed 'Best First'.
Re^3: sorting an array with decimal points
by Laurent_R (Canon) on Jan 15, 2018 at 20:12 UTC
    Your comment is relevant and right, but I would tend to agree with your update and I assumed that these numbers are version numbers rather than decimals, so that 1.4 1.10 1.31 would probably be the correct order for such data.

    But we will be able to figure out for sure only if the OP comes back and tells us.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1207264]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2018-07-16 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (335 votes). Check out past polls.

    Notices?