the list is a list of files by version. I need to keep the last 5 versions.
Jeff's code works fine except I am getting some empty strings at the beginning
that I have not figured out.
Here is what I have so far. Lines 34 and 39 are provide a print out for
troubleshooting. Once I get this fixed all I
need to do is shift the top five from the list and unlink the rest.
#!/usr/bin/perl
use warnings;
use strict;
opendir (REPOSITORY, '/usr/local/repository/dists/');
my @repositories = readdir (REPOSITORY);
closedir (REPOSITORY);
my $packageRepo;
my @values;
my @newValues;
foreach (@repositories)
{
$packageRepo = $_;
chomp ($packageRepo);
opendir (packageREPO,
"/usr/local/repository/dists/$packageRepo/non-free/binary-i386");
my @repoFiles = readdir (packageREPO);
close (packageREPO);
foreach (@repoFiles)
{
my $fileName = $_;
chomp ($fileName);
if ( /(.*)(([0-9][0-9])(-special)?\.([0-9])(-)([0-9]*))(.*)/)
{
push (@values, $2);
}
}
my %h;
foreach (@values)
{
push (@newValues, $_) unless $h{$_}++
}
foreach (@newValues){print "$_\n";}
my @new = map { $_->[0] }
sort { $b->[1] <=> $a->[1] }
map { [$_,(split/-/)[-1]] }
@newValues;
print "@new[0..4]\n";
}
Or for a line numbered version
http://rafb.net/p/asqgJo27.html
Tony Heal
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/