Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 31-08-2009
Member
 
Join Date: Apr 2009
Posts: 68
How to Parse CSV file using PERL

I have a bit of an issue trying to obtain some data from a csv file using PERL. I am trying to write a perl program which parses CSV files, and inserts the data into the DB. The problem is that i need to parse csv files which have fields spanning multiple lines. My script is placed in /usr/local. Can anyone here suggest me which rules should I keep in mind to parse CSV files.
Reply With Quote
  #2  
Old 31-08-2009
Member
 
Join Date: Apr 2008
Posts: 193
Re: How to Parse CSV file using PERL

CSV is a comma separated value data file is a physical ASCII file structure that contains records whose values are delimited or separated by commas. Traditionally CVS also uses optional double quotes around the values, and then, depending on which wicked version of Excel it's supposed to be incompatible with, more or less insane conventions for values with double quotes in them. CSV is a common file type which can be imported into spreadsheet applications such as MS-Excel, database applications such as MS-Access, and contact databases such as MS-Outlook, ACT, Goldmine, etc. The Text::CSV module provides functions for both parsing and producing CSV data.
Reply With Quote
  #3  
Old 31-08-2009
Member
 
Join Date: Jan 2009
Posts: 140
Re: How to Parse CSV file using PERL

When you are developing across platforms for a client that insists 'modules' are not allowed, and the perl program must be totally self contained.I guess the actual problem is that you are comparing the lines before throwing out the fields you don't want to include in the comparison. you find the reasoning for the way I explained the solution. CSV is one implementation of a delimited text file, which uses a comma to separate values (where many implementations of CSV import/export tools allow an alternate separator to be used;
Reply With Quote
  #4  
Old 31-08-2009
Member
 
Join Date: Jan 2009
Posts: 99
Re: How to Parse CSV file using PERL

I tried hand earlier in the day and was able to download and install the module. And it worked well too. But now i have to parse the XML file instead of csv. I guess the actual problem is that you are comparing the lines before throwing out the fields you don't want to include in the comparison. The simplest solution would be to read the uploaded file line-by-line and splitting the lines by commas, but this is not fool proof, just in case the one of the fields contain a comma which is not a delimiter but a part of the dataBefore you print, copy the print value to a hash, and if the hash already contains the value, don't print.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Parse CSV file using PERL"
Thread Thread Starter Forum Replies Last Post
Could not complete your request because the file-format module cannot parse the file Tamila Windows Software 6 13-07-2010 12:29 AM
Does java parse large text file Zeverto Software Development 3 30-07-2009 01:26 PM
Powershell script to parse system logs in text file SADIQ Operating Systems 2 02-06-2009 07:05 PM
Batch Script Text file parse tator.usenet@gmail.com Windows Server Help 5 25-03-2009 02:12 AM
Batch Script to parse lines in text file jntoner1@gmail.com Windows Server Help 8 28-01-2009 04:38 AM


All times are GMT +5.5. The time now is 01:08 AM.