Update: Looking at the other answers, seems I misunderstood the question? Please disregard.
Update 2: tye correctly pointed out that what I was trying to do (failing badly) was this:
sort{ eval "v$a" cmp eval "v$b" } @versions;
which is probably too hacky. :)
----
Since you have "version" strings, you can use the v notation to sort the strings, like this:
sort{ "v$a" cmp "v$b" } @versions;
This may seem a little hacky, but gets the job done.
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:
1.0.10
1.0.9
1.1.0
1.1.2
2.0.0
and you can just switch
$a and
$b to reverse the order.
You have moved into a dark place.
It is pitch black. You are likely to be eaten by a grue.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.