Trying to parse a file...need help 
Author Message
 Trying to parse a file...need help

Hi guys.  I receive flat files that have comma delimited fields.  The
number of fields is known, the delimiter is a comma.  Text fields are
delimited by a special charter (ASCII 214).  I have a problem where
sometimes the text fields have a line break in them so that if I was
expecting 15 fields on a line, I might get less.

I was going to use the split function to break up the fields, but I
know that text fields can have commas.

What would be the easiest way to split up the file into fields and be
able to recognize the text delimiters?

TIA,
Chester



Wed, 19 May 2004 00:05:39 GMT  
 Trying to parse a file...need help

Quote:

> Hi guys.  I receive flat files that have comma delimited fields.  The
> number of fields is known, the delimiter is a comma.  Text fields are
> delimited by a special charter (ASCII 214).  I have a problem where
> sometimes the text fields have a line break in them so that if I was
> expecting 15 fields on a line, I might get less.

Assuming that 214 delimits the start and end of each string you need
keep on reading until you have an even number of them in the record by
do something along the lines of:

while(<>) {
  $_ .= <> while !eof && tr/\326// % 2;
  # Process record.

Quote:
}
> I was going to use the split function to break up the fields, but I
> know that text fields can have commas.

Please see the answer given to that question in the FAQ.


Sat, 22 May 2004 02:33:01 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. need help reading and parsing wtmpx login accounting file

2. Reading and parsing a file help needed

3. Help Needed - dual text file parsing and comparing

4. Beginner in parsing a file need help..

5. Need Help Parsing ASCII File

6. Need help parsing a text file

7. Newbie-Doobie needs help parsing file

8. Newbie: Need help parsing html file for links

9. need help parsing two files

10. newbie trying to parse one file into three

11. Perl Newbie trying to parse file

12. Newbie needs help- trying to submit command-line function to perl script via web

 

 
Powered by phpBB® Forum Software