I have the list of xml files in a directory.
The file format is such that some of the files have a same "name" and prefixed with the random numbers.
Out of those files, using the xml parser, check for the date and time tag.
How can I compare the files with same "name" and delete the file which have the less time
filenames as 508.ids.xml
1508.ids.xml
1509.id123.xml
1400.id123.xml
#!/usr/bin/perl
use XML::Simple;
use ContentHelper;
use XML::Parser;
@files = `ls`;
# Sub substitution to check for duplicates
foreach $input_file (@grepNames){
chomp $input_file;
my $xml_parser = XML::Simple->new();
my $data = $xml_parser->XMLin($input_file);
my $Id = $data->{"root"}->{'id'};
my $date = $data->{'root'}->{'date'};
my $time = $data->{'root'}->{'time'};
### Please tell me how to add the condition here.
print "$input_file:$Id:$time:$date\n\n";
}
The above print command prints
9890.ids.xml:ids:70857:2004-10-02
9893.ids.xml:ids:70859:2004-10-02
9830.ids.xml:ids:2000:2004-10-02
9834.ids.xml:ids:4000:2004-10-01
Here how to delete the files,
9890.ids.xml:ids:70857:2004-10-02 and 9834.ids.xml:ids:4000:2004-10-02 as it has the less date and time
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.