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