in reply to Comparing Version Numbers

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.