I'm not sure this is possible even for a human to get right on the first try every single time. The package name can end in a number, which may or may not be preceded by what might seem to be a delimiting character (e.g., a hyphen in some cases). How to tell whether that's the end of the package name or the beginning of the version number? Sometimes knowledge of the development cycle of the package in question is required.

Of course, you can ignore those cases and assume that (as is the case for the majority of packages) any numbers separated from the package name by a delimiting character start the version number. That is the approach I would suggest. When it fails, you will just get extraneous entries in your logfile.

Still, comparing version numbers is hard. There is no standard for how they work. I mean, the basics are pretty straightforward (a.b.c.e comes after a.b.c.d if e>d), but a lot of packages do additional esoteric things with their version numbers. Alphas, betas, release candidates, prereleases, ... it's messy. One is tempted to say that alphabetic characters sort after numeric ones which sort after truncatedness, but then what do you do with a version like 3.23.41-5mdk? Ewww, that brings up the issue of forked versions... and what do you do when the same version of something is distributed with different patch options, and the patch options are postpended to the version number? In that case you want the package with the same patch options but the highest version number before them... [suppresses urge to go wash hands]

Still worse, most open-source packages consider the numbers between delimiters as integers, so that (e.g.) 7.11 will sort after 7.10 after 7.9 -- but there are some packages that do version numbering the other way, where 7.11 comes right after 7.1 but before 7.2 (i.e., ASCIIbetical sorting). This is especially common with packages whose lead developers started on platforms other than Unix. (Almost all version numbers in the DOS world were this way, for example, so programmers who used to work on DOS often still number that way.)


for(unpack("C*",'GGGG?GGGG?O__\?WccW?{GCw?Wcc{?Wcc~?Wcc{?~cc' .'W?')){$j=$_-63;++$a;for$p(0..7){$h[$p][$a]=$j%2;$j/=2}}for$ p(0..7){for$a(1..45){$_=($h[$p-1][$a])?'#':' ';print}print$/}

In reply to Re: Comapring Version Numbers by jonadab
in thread Comparing Version Numbers by Anonymous Monk

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.