praevalesco has asked for the wisdom of the Perl Monks concerning the following question:
use Date::Range; use Date::Simple (); print "Enter the userid or patient name (partials accepted): "; $userinput = <STDIN>; print "Enter the start date: "; $dateinput1 = <STDIN>; print "Enter the end date: "; $dateinput2 = <STDIN>; $date1 = Date::Simple->new($dateinput1); + # converts user inputted dates to simple d +ates $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 . "-" . $dateinput +1 . "_" . $dateinput2 . ".csv"; open (LOGFILE, $ORIGINALNAME) or die "can't open $ORIGINALNAME +"; while ($record = <LOGFILE>) { + # While reads records line by line from beg +inning to end of file @stringasarray = split(",", $record); + # Takes comma delimited line and breaks in +to array $cutdate = substr ($stringasarray[4],0,10); + # Identifies date field and chops the time o +ff 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 use +r inputed dates print "TEST!"; #open (REPORT, ">>$REPORTNAME") or die ("Canno +t open"); # Open the report file for writing #print REPORT $record; + # Print record to the file } } exit; } } + # Close files close(LOGFILE); close (REPORT); closedir(DIR);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: reg ex. problem - 2 variables
by grep (Monsignor) on Oct 04, 2006 at 20:03 UTC | |
by GrandFather (Saint) on Oct 04, 2006 at 20:30 UTC | |
by mreece (Friar) on Oct 04, 2006 at 23:19 UTC | |
by praevalesco (Initiate) on Oct 04, 2006 at 20:09 UTC | |
|
Re: reg ex. problem - 2 variables
by GrandFather (Saint) on Oct 04, 2006 at 20:05 UTC | |
|
Re: reg ex. problem - 2 variables
by graff (Chancellor) on Oct 05, 2006 at 02:07 UTC |