------------------------------------------------
On Mon, 21 Jul 2003 11:38:26 -0400, "Andrew Thomas" <[EMAIL PROTECTED]> wrote:

> Of course.... I apologize - I had meant to include that. Here it is, the 
> actual script is quite long so I've pared it down some to try and isolate 
> the problem. This is the whole script now and it is still having the same 
> problem.
> 
> 
> Text file is ~2800 lines like the following:
> 
> Lastname, Firstname|1|137|10_3|10/13/01|...........etc.
> (I have examined this carefully, and every line although very long does end 
> with a newline character)
> 
> And My script includes the following:
> 
> #!/usr/bin/perl
> 

Always have these:

use strict;
use warnings; 

> system "clear";

Not terribly portable but that is ok.

> print "Welcome to Andy's Data Processor...\n";
> 
> open(WRITEFILE, ">Output.txt") or die "Couldn't open WRITEFILE for 
> preparation.";
> 

You should include the special variable $! in your error strings so you know WHY the 
file couldn't be opened.

> print WRITEFILE "Patient Name|Study ID|Date of Birth|Medical Rec Num|Obs End 
> Date|Months of Obs|Month of Obs|Month of Year|Year|ID_Rec|CC Status|Acute 
> OV|ED Visits|Telemed Visits|WCC Visits|Non-Acute OV|\n";
> 
> print "Opening ReadFile(s)...\n\n\n";
> 
> open (READFILE,"events.txt") or die "Couldn't open READFILE.";
> 

See $! above.

> while(<READFILE>) {
> 
>       $string = <READFILE>;
> 

You are reading each line into the script twice with the above construct. First you 
read a line into the default $_ then read the next line into $string. This is why your 
script appears to skip lines (a common mistake).  You should combine the two.

while ($string = <READFILE>) {

Will do nicely.

>       $string =~ /^(\w+-*\w* *\w*, \w+)\|(\d+)\|(\d+)|/;
>       $patientName = $1;
> 
>       $studyID = $2;
> 
>       $dateOfBirth = $3;
> 
>        print WRITEFILE $patientName, $studyID, $dateOfBirth;
> }
> 
> close READFILE;
> 
> close WRITEFILE;
> 
> 
> That is the whole script - and it still outputs only half the lines. I'm 
> pretty much stumped - and starting to think that maybe perl isn't the best 
> solution for this project...... Hope someone out there can help.
> 

Whether Perl is the best solution is always up for debate, but it is definitely a good 
solution.  

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to