So here is the deal. I have a program that pulls 3 things from the STDIN... userid and two dates. These dates are then fed into DATE::SIMPLE and DATE::RANGE. I then look at all the files in a given directory and parse through these files for any occurences of the userid... if the userid is found, I then look at the date on this line and check if it is in the range of the two STDIN dates. If so, I write this line to a file. The majority of this program works, I am just getting tripped up on one line.... if ($record =~ m/$userinput/g). I use this piece of code to check the line in the file for the userid (or patient) given at STDIN. This line always returns false.
I have tried an alternate method using index, however it to always returns false. Popping the comma delimited line out into an array and directly comparing is a time consuming option as I allow the user to put in multiple types of input (i.e. patient or userid which are both different fields). Any quick fixes are greatly appreciated.
Thanks,
Nick
Full Code:
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);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.