473,390 Members | 1,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

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 4530
numberwhun
3,509 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,509 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

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

Similar topics

4
by: Frank Millman | last post by:
Hi all I need to generate potentially large reports from a database, and I want to offer the option of print preview before actually printing (using wxPython). I figure that the best way to...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
7
by: | last post by:
In the beginning we had Ini files. Later we had registery files. Now have xml files and our read-only myapp.config file. My question now, is what is the best way to store and load user and...
4
by: ESPN Lover | last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one way preferred over the other and why? Thanks. using System; using System.IO; class Test { public static void...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
17
by: | last post by:
I have an app that retrieves data from an Access database. At the moment I have the SQL string as a Const in my app. I understand this is not best practice. I don't want the user to have access to...
11
by: Tom | last post by:
I am planning on adding a Preferences form to my application and using the Property Grid to display the preferences to the user. What do you think would be the best way to save these preferences...
3
by: gordon | last post by:
Hi I am looking to store some details about a user's configuration choices, in particular the place where they have installed some data files, the OS that they use, and their Windows user name. ...
4
by: TC | last post by:
Hey All, I have to read .csv files and display them in a DataGridView. Currently, I'm dumping the data into a DataTable but it's causing problems because the engine is automatically converting...
4
by: Brian | last post by:
HI, I have two sets of data, the largest set of data contains 370 rows... both sets only have two columns. I want to be able to distribute the data with my applaction. The other option, would be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.