in reply to Delete the file with checking the value
#!/usr/bin/perl my %hash; while (<DATA>) { my ($input_file, $time, $date) = split ' '; # determine common part of file names my $common = $input_file; $common =~ s/^\d+//; # remove leading number # collect info (name, timestamp) in hash, keyed by common part of +file names push @{$hash{$common}}, [ $input_file, sprintf("%s %6d",$date,$tim +e) ]; } # use Data::Dumper; # print Dumper \%hash; # debug for my $k (keys %hash) { # for all file sets # sort by timestamp my @files = sort {$b->[1] cmp $a->[1]} @{$hash{$k}}; # remove most recent file (the one to keep) from list shift @files; # delete remaining (older) files unlink map $_->[0], @files; } __DATA__ 508.ids.xml 70857 2004-10-02 1508.ids.xml 70859 2004-10-02 1509.id123.xml 2000 2004-10-02 1400.id123.xml 4000 2004-10-01
(I left out the XML stuff, as the OP doesn't seem to have problems with that part.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Delete the file with checking the value
by Anonymous Monk on Feb 28, 2010 at 05:40 UTC | |
by almut (Canon) on Feb 28, 2010 at 09:45 UTC |