This might work. The idea is to expand any groups of numerals in the name with some arbitrarially large number of leading zeros--I used 5 which maybe overkill. That way, the filenames will be directly comparable using standard string comparision operators.

I also built the keys to the two hashes by removing any digits, from the names to simplify the lookup of one has against the other. I stored the expanded filename, along with the original in an anonymous array keyed by the reduced filename. To clarify for xpdf-1.01-10, the structure contains:

{'xpdf-.-' => ['xpdf-00001.00001-00010', 'xpdf-1.01-10'];}

That should allow quick, accurate lookup of package names by key, gives a value for each that can be compared using gt (or cmp etc) and retains the original value for display or logging.

I'm sure that there are examples of packages that will break this, but they are probably the exception rather than the rule.

#! perl -slw use strict; my %current = map{ (my $key = $_) =~ s[[\d.]+][]g; (my $comp = $_) =~ s[(\d+)][ sprintf'%05d', $1]ge; $key => [ $comp, $_ ]; } qw[ zip-2.3.1-14 xpdf-1.01-8 ggv-1.99.8-2 libpng-devel-1.2.2-8 xvattr-1.3-ogle1 ]; my %updates = map{ (my $key = $_) =~ s[[\d.]+][]g; (my $comp = $_) =~ s[(\d+)][ sprintf'%05d', $1]ge; $key => [ $comp, $_ ]; } qw[ WindowMaker-0.80.1-5 lynx-2.8.5-7.1 xpdf-1.01-10 ggv-1.99.9-5 xvattr-1.4-ogle1 libpng-devel-1.2.2-9 ]; for my $pkg (keys %current) { if (exists $updates{$pkg} and $updates{$pkg}[0] gt $current{$pkg}[0] ){ print 'Update ', $updates{$pkg}[1], $/ , ' available for: ', $current{$pkg}[1]; } } __END__ C:\test>240384 Update xvattr-1.4-ogle1 available for: xvattr-1.3-ogle1 Update xpdf-1.01-10 available for: xpdf-1.01-8 Update ggv-1.99.9-5 available for: ggv-1.99.8-2 Update libpng-devel-1.2.2-9 available for: libpng-devel-1.2.2-8

Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

In reply to Re: Comapring Version Numbers by BrowserUk
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.