Hi,
Date::Format from CPAN can aid you in formatting dates. As for Modification times, you want to use the stat function.
To print the modification date of a file in dd/mm/yy format you could use:
use Date::Format;
$file = '...filepath...';
$modTimeInSec = (stat $file)[9];
print time2str("%d/%m/%y", $modTimeInSec);
For more info on formatting dates, check the documentation for Date::Format.
Your second question is a little more difficult. I will give you some places to look, but how you want to do it will ultimately depend on how exactly you want this to work.
How does the user enter the date range? Is it an exact date-time, or the current day, or all files in a month? etc. What ever you decide, you may want to use Date::Parse to help you parse dates and times.
Once you have a start time and end time in seconds since epoch, then you need to search through your files. For example, to get and array of files in the current directory that were modified between $startTime and $endTime, you might use the following:
@files = grep {
my $mod = (stat $_)[9];
$startTime <= $mod && $mod <= $endTime
} <*.*>;
This is a quick example and isn't perfect. The glob operator (<*.*>) specifies a glob pattern to match. If you want to search through directories recursively, check out File::Find.
Sorry, I can't be more of a help with your second problem, but it really depends on a better explanation of what you are trying to do. I hope my tips help.
Ted Young
($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
|