use Date::Range; use Date::Simple (); print "Enter the userid or patient name (partials accepted): "; $userinput = ; print "Enter the start date: "; $dateinput1 = ; print "Enter the end date: "; $dateinput2 = ; $date1 = Date::Simple->new($dateinput1); # converts user inputted dates to simple dates $date2 = Date::Simple->new($dateinput2); $range = Date::Range->new($date1, $date2); $dirname = "../normalized/"; opendir(DIR, $dirname) or die "can't opendir $dirname"; while ( defined ($file = readdir DIR) ) { next if $file =~ /^[\.nSo]/; # ensures that folders with n, S or o arent processed $ORIGINALNAME = "../normalized/" . "$file"; $REPORTNAME = "../normalized/" . $userinput . "-" . $dateinput1 . "_" . $dateinput2 . ".csv"; open (LOGFILE, $ORIGINALNAME) or die "can't open $ORIGINALNAME"; while ($record = ) { # While reads records line by line from beginning to end of file @stringasarray = split(",", $record); # Takes comma delimited line and breaks into array $cutdate = substr ($stringasarray[4],0,10); # Identifies date field and chops the time off the end $date3 = Date::Simple->new($cutdate); # converts the date to a simple date if ($record =~ m/$userinput/g) { print "TEST2!"; if ($range->includes($date3)) { # tests if date from file is within the user inputed dates print "TEST!"; #open (REPORT, ">>$REPORTNAME") or die ("Cannot open"); # Open the report file for writing #print REPORT $record; # Print record to the file } } exit; } } # Close files close(LOGFILE); close (REPORT); closedir(DIR);