Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
While searching a text file for dates, this program prints the text surrounding the date as well, but is only supposed to print the date. I have obviously missed something, any suggestions would be appreciated.
$dir='C:/texts/'; opendir(directory,$dir) or die "cant"; while($file=readdir directory){ next if $file=~/^\./; $rfname=$dir.$file; # print "Found file: '$rfname'\n"; open (CONT, $rfname); while (<CONT>){ if($_=~m/[0-3]?[0-9(th)?(st)?(nd)?(rd)?]\s+(Jan(uary)?|Feb(ruary)? +|Mar(ch)?|Apr(il)?|May|Jun(e)?|Jul(y)?|Aug(ust)?|Sep(tember)?|Oct(obe +r)?|Nov(ember)?|Dec(ember)?)\s+[0-9]?[0-9]?[0-9][0-9]/ig){ print "$file\t $_\n"; } elsif($_=~m/(Jan(uary)?|Feb(ruary)?|Mar(ch)?|Apr(il)?|May|Jun(e)?| +Jul(y)?|Aug(ust)?|Sep(tember)?|Oct(ober)?|Nov(ember)?|Dec(ember)?)\s+ +[1-3]?[0-9](th)?(nd)?(st)?(rd)?\s+[0-9]?[0-9]?[0-9][0-9]/ig){ print "$file\t $_\n"; } } }
Petruchio Thu Jul 12 01:55:32 EDT 2001: Added code tags.
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: $_
by jjhorner (Hermit) on Jun 21, 2000 at 16:46 UTC | |
Re: $_
by raflach (Pilgrim) on Jun 21, 2000 at 17:15 UTC | |
Re: $_
by davorg (Chancellor) on Jun 21, 2000 at 16:48 UTC | |
by Adam (Vicar) on Jun 22, 2000 at 05:21 UTC | |
Re: $_ ('x' regex modifier)
by Russ (Deacon) on Jun 22, 2000 at 01:18 UTC |
Back to
Seekers of Perl Wisdom