Re: Picking up files based on datestamp
by johngg (Canon) on Sep 19, 2007 at 08:40 UTC
|
As well as using a regular expression, as suggested by moritz, have a look at opendir, readdir and grep. You should be able to arrive at something along the lines of
my @filesWanted =
grep { -f && m{your regex} } readdir $dirHandle;
I hope this is of use. Cheers, JohnGG | [reply] [d/l] |
Re: Picking up files based on datestamp
by siva kumar (Pilgrim) on Sep 19, 2007 at 08:42 UTC
|
Identify the "yyyymmdd" value from the file name using the below perl regex.
$filename = "ccsCDRFileGenerator-0-24161-1176950330-17914920070419_2.C
+DR";
($yyyymmdd) = $filename =~ m/\d+(\d{8})\_\d+\.CDR$/;
print "DATE is : $yyyymmdd \n"
Using the DateTime::Precise module, identify yesterday's
"yyyymmdd" value. Then you can pickup the files as you want..
| [reply] [d/l] |
Re: Picking up files based on datestamp
by moritz (Cardinal) on Sep 19, 2007 at 08:05 UTC
|
| [reply] |
Re: Picking up files based on datestamp
by subhankar (Novice) on Sep 19, 2007 at 10:09 UTC
|
Dear all
Thank you all for your inputs. I can manage the regexp part, but the main problem is identifying yesterday's "yyyymmdd" value.
Sivakumar: I cant install any external modules as of now (sucks, but well..) and I dont have the DateTime::Precise module.
How do I identify yesterday's $yyyymmdd value using the default modules/functions?
Help!
Thanks & regards,
Subhankar | [reply] |
|
|
you can find yesterday's yyyymmdd using
my $timestampminus = time - 24 * 60 * 60;
my ($year, $month, $day) = (localtime($timestampminus))[5,4,3];
$year += 1900;
$month++;
print "Yesterday was $year$month$day.\n";
| [reply] [d/l] |
|
|
my ($day, $month, $year) =
(localtime(time() - 86400))[3, 4, 5];
$month += 1;
$year += 1900;
I hope this is of use. Cheers, JohnGG | [reply] [d/l] |
|
|
| [reply] |
Re: Picking up files based on datestamp
by subhankar (Novice) on Sep 19, 2007 at 11:35 UTC
|
Dear Monks,
Thank you all for your excellent tips!! I am so glad I am doing perl :-)
Cheers!
Subhankar | [reply] |
Re: Picking up files based on datestamp
by subhankar (Novice) on Sep 21, 2007 at 06:00 UTC
|
Dear Monks
Please help me a little more with the dates.
Using the localtime(time) option, currently I am getting the month as a sigle digit i.e. September as 9.
But how do I get the month as 09?
($day, $month, $year) = (localtime(time() - 86400))[3, 4, 5];
$month += 1;
$year += 1900;
Thanks & regards,
Subhankar | [reply] [d/l] |
|
|
$month = sprintf("%02d",$month);
| [reply] [d/l] |
|
|
Thanks Siva!!
I had already figured that out :-) I thought there could be a way within localtime(time) itself.
Thanks & regards,
Subhankar
| [reply] |