Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: sorting an array with decimal points

by Marshall (Canon)
on Jan 15, 2018 at 01:44 UTC ( [id://1207251]=note: print w/replies, xml ) Need Help??


in reply to sorting an array with decimal points

To sort the input array, try this:
Compare decimal numbers for each line.
#!/usr/bin/perl use strict; my @names = qw (Patch_8.0 Patch_9.3 Patch_10.2 Patch_1.0 Patch_2.0 Pat +ch_3.1 Patch_5.0 Patch_4.2 Patch_6.0 Patch_7.0); my @patches = sort { my ($A) = $a=~ m/([\d\.]+)/; my ($B) = $b=~ m/([\d\.]+)/; $A <=> $B}@names; print "$_\n" for @patches; __END__ Patch_1.0 Patch_2.0 Patch_3.1 Patch_4.2 Patch_5.0 Patch_6.0 Patch_7.0 Patch_8.0 Patch_9.3 Patch_10.2

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1207251]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found