in reply to date as part of filename

zac_carl:

Extracting the date from the filename should be simple enough, something like this ought to do it:

my $fname = 'abcd1.20110429-2345'; my $date = 'NOT FOUND'; if ($fname =~ /(20\d{6})-\d{4}/) { $date = $1; } print $date,"\n";

For comparing date ranges, I'd suggest hitting up CPAN for some modules like DateTime.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: date as part of filename
by zac_carl (Acolyte) on May 12, 2011 at 22:44 UTC
    Thanks roboticus .. I dont have any modules CPAN MODULES install for the date though. I would have multiple files like this and want to reverse sort them according to the extracted date and from subtract them to identify <=7 date files and process them
      Time::Piece is a core module, and should be able to parse (strptime), format (strftime), and subtract days from an arbitrary date.

      zac_carl:

      While I would suggest using some CPAN goodness, if you're set against it, then you ought to read perldoc perlfunc and review interesting functions like localtime to see how you might accomplish the job.

      ...roboticus

      When your only tool is a hammer perl, all problems look like your thumb reimplementing CPAN (poorly).