http://qs1969.pair.com?node_id=19212

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.