The suggestion of using Text::CSV_XS was the winner.  This is a
very simple module to use.  Thanks for the feedback though.

Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com



-----Original Message-----
From: Ravi Kongara [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 07, 2004 2:05 PM
To: NIPP, SCOTT V (SBCSI)
Cc: [EMAIL PROTECTED]
Subject: Re: Parsing question...


What i understood from your question is , you want to split strings that

have comma within
quotes. Forgive me if i'm wrong.

If elements of @data are re-split  , you can get multiple fields from
it.

<  ...snip...  >
my @new_data;
while (<DATA>) {
  @data = split(/,\s*/);
   foreach my $string ( @data ) {
     @temp = split /,\s*/, $string;
     push @new_data, @temp;
   }
  print "$data[1]\n";
}
<   ...snip...  >

there may be better solutions, though, as i've never dealt with CSV
files.

regs,
Ravi

NIPP, SCOTT V (SBCSI) wrote:

>       This isn't specifically a DBI question, but it is a part of a
>database script I am writing.  I am parsing a CSV file and populating a
>MySQL database table.  The problem I have run into is that a couple of
>lines of data have a comma in a filed that is in quotes, such as "First
>part, second part".  This makes it difficult to parse the CSV file on
>commas like my intention was.  Could someone help me figure out how to
>parse this?  Thanks.  
>       Basically, I am reading in the file in a 'while' loop.  I am
>then splitting the line into an array using the 'split' function.  The
>next step is to simply populate the database table with the fields.
>Here is the 'split' I am currently using.
>
><  ...snip...  >
>while (<DATA>) {
>  @data = split(/,\s*/);
>  print "$data[1]\n";
>}
><   ...snip...  >
>
>       Thanks in advance for the help.
>
>Scott Nipp
>Phone:  (214) 858-1289
>E-mail:  [EMAIL PROTECTED]
>Web:  http:\\ldsa.sbcld.sbc.com
>
>
>  
>

Reply via email to