Dear Esteemed monks,
I'm working on a task which is as below:
* Generate a list of dates from a given start date to a given end date
* Get a list of files for each of the item(these are directories) in the csv file
* Once I have a the two arrays, i.e one array consisting of a list of dates
and the second array with the list of files for a directory,I have to check for the existence of each of the dates from the first array in the second array.
* The following are the structures of the dates array and files array contains the filenames as
@datelist = ("20030901", "20061017", "20050406", "20070101", "20080202");
@fileslist = ("DIR22.20060816", "DIR22.20050919", "DIR22.20061017", "DIR22.20060516", "DIR22.20050406");
I am using grep to check the existence of dates from the first array in the second array.
Below is the code I'm using, please let me know whether this approach is correct or is there any other better way:
#!/usr/bi/perl
$driver = "./dirlist.csv";
open DRV , $driver || die "Cannot open $driver: $!";
while( <DRV> ){
chomp;
my ($dirname) = shift;
checkExistingDates($dirname);
}
close DRV;
sub checkExistingDates{
my $dirname = shift;
my @datelist = ("20030901", "20061017", "20050406", "20070101", "2
+0080202");
#the file list should be read from the $dirname, for testing using
+ hard values
my @fileslist = ("DIR22.20060816", "DIR22.20050919", "DIR22.200610
+17", "DIR22.20060516", "DIR22.20050406");
my @matched;
foreach my $date (@datelist}){
@matched = grep{$date} @fileslist;
}
print Dumper @matched;
}
Thanks in advance
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.