in reply to Finding the latest available version of a program

I wrote something similar to cull old versions of RPMs from the directory where I download patches. The other posters are right about the problems with version numbers. I solved it by storing the version in the hash, and comparing the version whenever a duplicate was found. The downside is that the resulting hash ONLY has the latest version number for each application. That might or might not be an issue for you. To make the version numbers work right, I split them on /\./, so they could be compared as numbers. If you're not doing this with RPMs, you can just change the way the initial hash is loaded.
my %rpms; my %files; foreach my $file (<*.rpm>) { # RPM-SPECIFIC STUFF: my @result = `rpm -qp --queryformat "%{NAME}/%{ARCH}/%{VERSION}.%{RE +LEASE}\n" $file`; my ($name, $arch, $version) = split /\//, $result[0]; # END RPM-SPECIFIC STUFF $name .= ":" . $arch; if ( exists $rpms{$name} ) { #decide which one we like better: my @a = split /\./, $version; my @b = split /\./, $rpms{$name}; my $i=0; my $max = $#a > $#b ? $#a : $#b; while ($i <= $max) { if ( $a[$i] eq $b[$i] ) { $i++; next; } if ( $a[$i] lt $b[$i] ) { print "rm -f $file\n"; last; } else { my $rm = "rm -f $files{$name}"; print "$rm\n"; `$rm` if lc($ARGV[0]) eq 'rm'; # or whatever else you want to do with old files. last; } $i++; } } else { $rpms{$name} = $version; $files{$name} = $file; } }
Hope it helps.

--
Spring: Forces, Coiled Again!