943,983 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 11739
  • Perl RSS
Jul 20th, 2006
0

Perl CSV question

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hotshotcity is offline Offline
2 posts
since Jul 2006
Jul 22nd, 2006
2

Re: Perl CSV question

Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Jul 27th, 2006
0

Re: Perl CSV question

Thanks. this was what i needed!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hotshotcity is offline Offline
2 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: How to invoke a perl program from a perl program.
Next Thread in Perl Forum Timeline: OpenFTS





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC