in reply to Sorting An Array of Versions
Update 2: tye correctly pointed out that what I was trying to do (failing badly) was this:
which is probably too hacky. :)sort{ eval "v$a" cmp eval "v$b" } @versions;
----
Since you have "version" strings, you can use the v notation to sort the strings, like this:
This may seem a little hacky, but gets the job done.sort{ "v$a" cmp "v$b" } @versions;
It vorks like this: v2.0.0 is the same thing as chr(2).chr(0).chr(0), so we can do a stringwise compare, cmp and thus sort these correctly. The result is:
and you can just switch $a and $b to reverse the order.1.0.10 1.0.9 1.1.0 1.1.2 2.0.0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re2: Sorting An Array of Versions
by tye (Sage) on Mar 12, 2002 at 19:19 UTC | |
by Dog and Pony (Priest) on Mar 12, 2002 at 19:23 UTC |