#!/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.)


In reply to Re: Delete the file with checking the value by almut
in thread Delete the file with checking the value 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.