mrchad has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to search through all my files for a string that contains a date. I want to be able to find any file with a date that falls during this current week. I am able to pull the files that contain todays date, but I can't seem to search for more than one at a time. Any suggestions on how to accomplish this?
@days=(Sun,Mon,Tue,Wed,Thu,Fri,Sat); @months=(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec); $time=time; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($time) +; $year += 1900; $eday = $mday + 6; $sdate ="$months[$mon] $mday"; $edate="$months[$mon] $eday"; #-- Output ----------------------------------- print header(); print start_html(); print "\n<p>The following files contain content that will expire durin +g $sdate - $edate:</p>\n<ul>\n"; find( sub { return if($_ =~ /^\./); return unless($_ =~ /\.(cfm|htm|cfml|html|txt)/i); stat $File::Find::name; return if -d; return unless -r; open(FILE, "< $File::Find::name") or return; my $string = <FILE>; close (FILE); return unless ($string =~ /\Q$edate/i); my $page_title = $_; if ($string =~ /<title>(.*?)<\/title>/is) { $page_title = $1; } my $foundFile = $File::Find::name; print "<li><a href=\"$foundFile\">$File::Find::name</a></li>\n +"; }, '/inetpub/mysite');

Replies are listed 'Best First'.
Re: files that include date range
by ehdonhon (Curate) on Apr 23, 2002 at 15:17 UTC
Re: files that include date range
by derby (Abbot) on Apr 23, 2002 at 14:21 UTC
    Not elegant but ...

    $regex = ""; foreach $day ( 0 .. 6 ) { $regex .= $months[$mon] . $mday + $day . "|"; } chop( $regex ); ... return unless ( $string =~ /\Q$regex/oi ); ...

    -derby