Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Version Sorting

by TedPride (Priest)
on May 30, 2006 at 10:06 UTC ( [id://552445]=note: print w/replies, xml ) Need Help??


in reply to Version Sorting

The following does what you need:
use strict; use warnings; chomp(my @version = <DATA>); print join "\n", @version = map { join '.', unpack 'C*', $_ } sort map { pack 'C*', split /\./, $_ } @version; __DATA__ 1.2.3 1.3.4 1.2.31 1.12 1.12.1 1.12.12
Basically, it converts each number part to a byte value, so the resulting version string is fixed-width (for the number of fields it has) and can be efficiently sorted. Then it sorts and converts back.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found