Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: sorting an array with decimal points

by salva (Canon)
on Jan 15, 2018 at 08:04 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1207264]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2024-03-28 10:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found