On Tue, 21 Sep 2004, Ricardo SIGNES wrote:

>       my @columns = split(/,/, <$csv_file>);

That's optimistic.

    id,name,title
    42,"Adams, Douglas","Author, HHGTTG et al"

    id;name;title
    42;Adams, Douglas;Author, HHGTTG et al

Etc. There are various ways -- most ad hoc -- of embedding commas in CSV 
files, nearly all of which will fail if you just split on commas. 

One good way around this is to use DBD::CSV, and just write normal DBI 
code that treats your CSV file as if it were a SQL database. This works 
surprisingly well, and is much easier to do if you already know DBI.

Splitting on commas, as above, is the "easy" way to do it, but it should 
really only be done if you *know* your data file is well behaved, i.e. 
you wrote it, you've validated it, it has no funny rows, etc. If there's 
any reasonable chance that the data gets "funny", things get much harder 
to do right and you're better off going with a module like DBD::CSV.


-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to