| | |
Perl CSV question
![]() |
•
•
Join Date: Jul 2006
Posts: 2
Reputation:
Solved Threads: 0
Hello All,
This post is releated to the help provided to heatherc3 (Suggestions for perl resources? Dealing with csv data.)
Posted May 18th 2006 04:01 PM, and I could use the solutions posted there, if I could get to that as a starting point.
I want to work on a comma delimited file, however some of the data fields have a comma within the data.
The fields with commas within them are the first two in the record.
They are always enclosed by double quotes.
The file format looks something like the following....
"field1 random text, more text","field2 random text, more text in field2", field3, field4,field5
"field1 random text without comma","field2 random text, more text in field2", field3, field4,field5
"field1 random text, more text","field2 random text without comma", field3, field4,field5
"field1 random text without comma","field2 random text without comma", field3, field4,field5
If I do a split on comma I get varying number of fields as
line one above in my test file has 6 commas
line two above in my test file has 5 commas
line three above in my test file has 5 commas
line four above in my test file has 4 commas.
I was thinking the best way to approch this would be to search and replace commas, but only if they are enclosed within double quotes?
Can anybody tell me if that is the best way?
Thanks
This post is releated to the help provided to heatherc3 (Suggestions for perl resources? Dealing with csv data.)
Posted May 18th 2006 04:01 PM, and I could use the solutions posted there, if I could get to that as a starting point.
I want to work on a comma delimited file, however some of the data fields have a comma within the data.
The fields with commas within them are the first two in the record.
They are always enclosed by double quotes.
The file format looks something like the following....
"field1 random text, more text","field2 random text, more text in field2", field3, field4,field5
"field1 random text without comma","field2 random text, more text in field2", field3, field4,field5
"field1 random text, more text","field2 random text without comma", field3, field4,field5
"field1 random text without comma","field2 random text without comma", field3, field4,field5
If I do a split on comma I get varying number of fields as
line one above in my test file has 6 commas
line two above in my test file has 5 commas
line three above in my test file has 5 commas
line four above in my test file has 4 commas.
I was thinking the best way to approch this would be to search and replace commas, but only if they are enclosed within double quotes?
Can anybody tell me if that is the best way?
Thanks
![]() |
Similar Threads
- Perl question (Perl)
- Regular expression doesn't make sense (Perl)
- win32::ole and excel question (Perl)
- Suggestions for perl resources? Dealing with csv data. (Perl)
- Creating objects in Perl (Perl)
Other Threads in the Perl Forum
- Previous Thread: How to invoke a perl program from a perl program.
- Next Thread: OpenFTS
| Thread Tools | Search this Thread |






