develooper Front page | perl.dbi.users | Postings from February 2001

Re: comments in 'csv' files

Thread Previous
From:
Jeff Zucker
Date:
February 22, 2001 14:16
Subject:
Re: comments in 'csv' files
Message ID:
3A958F85.750AC74F@vpservices.com
Robert Grant wrote:
> 
> Is it possible to have DBD:CSV ignore comment lines and blank lines
> within the 'csv' file?
> 
> For example,
> ------------------
> #Comments
> #Comments
> Field1,Field2
> data1,data2

Well DBD::CSV (or DBD::AnyData) won't ignore the comments, but you can
use those DBDs and ignore the comments yourself.  You can't have the
comments above the field names, but below the field names you can just
have the comment treated as a single field record (put quotes around it
if it contains commas):

Field1,Field2
#Comment
"#Comment Long comment with commas, etc."
data1,data2

Then weed out the comments in your SELECT:

my $sth = $dbh->prepare(qq{
    SELECT *
      FROM table1
     WHERE NOT Field1 LIKE '#Comment%'
});

-- 
Jeff

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About