Is there some reason you aren't using DBD::CSV or its parser (Text::CSV_XS), which handle this and a number of other problem issues with parsing CSV? Why reinvent the wheel?

--
Jeff

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