469,320 Members | 2,153 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,320 developers. It's quick & easy.

Best way to read a csv file?

219 100+
I've got a csv file that I need to reformat using a perl script. I need to take the 14th and 16th positions and combine them together into one field with some characters. I'm still new to perl so I'm not sure the best practice. I was going to use a do loop and to get to the 14th "," value. Then read the chars up to the next ",". Skip the next comma value, then do the same for position 16.

I'm assuming there's a better way to do this.
Nov 21 '07 #1
5 4480
numberwhun
3,503 Expert Mod 2GB
I've got a csv file that I need to reformat using a perl script. I need to take the 14th and 16th positions and combine them together into one field with some characters. I'm still new to perl so I'm not sure the best practice. I was going to use a do loop and to get to the 14th "," value. Then read the chars up to the next ",". Skip the next comma value, then do the same for position 16.

I'm assuming there's a better way to do this.
This being Perl, there is always TIMTOWTDI. That said, you could always use the DBI interface and include the DBD::CSV module which treats a CSV file as a database, allowing you easier access to each entry. I haven't used it, but read about it.

Regards,

Jeff
Nov 21 '07 #2
KevinADC
4,059 Expert 2GB
look into Text::CSV or Text::CSV_XS

You can find them on CPAN as well as other repositories:

http://search.cpan.org/
Nov 21 '07 #3
dmorand
219 100+
Cool thanks. I'll check that out.
Nov 21 '07 #4
KevinADC
4,059 Expert 2GB
This being Perl, there is always TIMTOWTDI. That said, you could always use the DBI interface and include the DBD::CSV module which treats a CSV file as a database, allowing you easier access to each entry. I haven't used it, but read about it.

Regards,

Jeff
If a person is already familiar with SQL or their CSV file is structure as such, that is an option, interestingly, DBD::CSV module is a wrapper for Text::CSV_XS.
Nov 21 '07 #5
numberwhun
3,503 Expert Mod 2GB
If a person is already familiar with SQL or their CSV file is structure as such, that is an option, interestingly, DBD::CSV module is a wrapper for Text::CSV_XS.
Oh, ok. Thanks! Wasn't aware.
Nov 21 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Frank Millman | last post: by
136 posts views Thread by Matt Kruse | last post: by
4 posts views Thread by ESPN Lover | last post: by
10 posts views Thread by jojobar | last post: by
3 posts views Thread by gordon | last post: by
4 posts views Thread by TC | last post: by
4 posts views Thread by Brian | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.