473,503 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best way to read a csv file?

219 New Member
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 4531
numberwhun
3,509 Recognized Expert Moderator Specialist
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 Recognized Expert Specialist
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 New Member
Cool thanks. I'll check that out.
Nov 21 '07 #4
KevinADC
4,059 Recognized Expert Specialist
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 Recognized Expert Moderator Specialist
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
6756
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
9201
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
6562
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
2711
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
3416
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
7999
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
2394
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
2123
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
1916
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
2010
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
7203
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
7087
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7281
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,...
1
6993
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...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1514
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
383
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.