The basic approach to this sort of problem is to normalize the strings so you can just do a simple alphabetic sort on them. This means padding out the data so that the sort will work correctly. I am not sure exactly how the letters are supposed to sort but something like this will get you on track.

@data = qw( mozilla-1.4.2-3.0.2 mozilla-1.40-3.0.18 mozilla-1.4.2r-3.0 +.2 mozilla-1.4g-3.0.18 mozilla-1.4.1-3.0.2 mozilla-1.4-3.0.7 mozilla-1.4g-3.1.18 mozilla-1.4-3.0.1 mozilla-1.4-3.0.71 mozilla-1.4.2s-3.0.2 mozilla-1.4-3.0.18 mozilla-1.4a-3.0.1 +8 ); @data = map{[ normalize($_), $_]}@data; @data = sort { $a->[0] cmp $b->[0] } @data; printf "%s\t%s\n", $_->[0], $_->[1] for @data; sub normalize { my $str = shift; $str =~ s/(\-\w+\.\w+)\-/$1.0-/; #return join '', map{ sprintf "%3s", $_ }split m/[\-\.]/, $str; return join '', map{ s/^(\d+)(\w*)$/sprintf "%3s%1s", $1, $2?$2:' +'/e; $_ }split m/[\-\.]/, $str; } __DATA__ mozilla 1 4 0 3 0 1 mozilla-1.4-3.0.1 mozilla 1 4 0 3 0 7 mozilla-1.4-3.0.7 mozilla 1 4 0 3 0 18 mozilla-1.4-3.0.18 mozilla 1 4 0 3 0 71 mozilla-1.4-3.0.71 mozilla 1 4 1 3 0 2 mozilla-1.4.1-3.0.2 mozilla 1 4 2 3 0 2 mozilla-1.4.2-3.0.2 mozilla 1 4 2r 3 0 2 mozilla-1.4.2r-3.0.2 mozilla 1 4 2s 3 0 2 mozilla-1.4.2s-3.0.2 mozilla 1 4a 0 3 0 18 mozilla-1.4a-3.0.18 mozilla 1 4g 0 3 0 18 mozilla-1.4g-3.0.18 mozilla 1 4g 0 3 1 18 mozilla-1.4g-3.1.18 mozilla 1 40 0 3 0 18 mozilla-1.40-3.0.18

cheers

tachyon


In reply to Re: Version checking by tachyon
in thread Version checking by jasonc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.