On Jul 21, Andrew Thomas said:

>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.

But the person (I think) you're replying to already TOLD you the problem.
You've got:

>while(<READFILE>) {

and then you've got:

>       $string = <READFILE>;

The while() line reads a line into $_, and then you read the NEXT line
into $string.

>       $string =~ /^(\w+-*\w* *\w*, \w+)\|(\d+)\|(\d+)|/;

You've got a | at the end of your regex that I THINK you want to be \|.

>       $patientName = $1;
>       $studyID = $2;
>       $dateOfBirth = $3;
>       print WRITEFILE $patientName, $studyID, $dateOfBirth;

You're missing the newline after you print those things.  And you don't
need to use separate variables -- you could just use $1, $2, and $3.  And
don't you want a | between these fields still?

And you're using the $DIGIT variables without being sure the regex matched,
which isn't a smart idea.

>}

I'd rewrite the loop as follows:

  while (<READFILE>) {
    if (/^(\w+-*\w* *\w*, \w+)\|(\d+)\|(\d+)\|/) {
      print WRITEFILE "$1|$2|$3\n";
    }
  }

But maybe you could just write:

  while (<READFILE>) {
    chomp;
    my @fields = split /\|/;
    print WRITEFILE join("|", @fields[0..2]), "\n";
  }

Perhaps if you tell us exactly what your program is supposed to do, we can
help you write it better.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]



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

Reply via email to