in reply to Re: DBD::CSV Update
in thread DBD::CSV Update
The skip_rows option will skip valid CSV-rows (and will croak otherwise). Though the hint is good, I think that it doesn't currently do as required by the OP: it skips CSV lines after the header.
When not passing the col_names like you did, it will skip the count of lines as passed like this after reading the header line, so in given example, that would still result in just 3 fields. That obviously needs a new option that would skip lines before the header line in whatever format, so a CSV file like this:
This file holds the report for sales over August 2013 id,count,description,price FAIL,,Placeholder,0.00 \N,,, 10D2,4,Drill 9mm,0.80 11E1,1,Festool DRC 18/4.515.15
could be opened and correctly dealt with with code like:
#!/usr/bin/perl use 5.20.0; use warnings; use DBI; my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_dir => ".", csv_auto_diag => 1, }); $dbh->{csv_tables}{stock} = { file => "stock.csv", skip_rows => 2, skip_before => 3, # nonexisting option # look ma, no col_names }; my $sth = $dbh->prepare ("select * from stock"); $sth->execute; while (my $row = $sth->fetch) { say "@$row"; } $dbh->do ("update foo set price = 420 where id = '11E1'"); $dbh->disconnect;
The new option however has no control over the format of the lines. I'll consider adding a new option for this.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: DBD::CSV Update
by soonix (Chancellor) on Jun 01, 2015 at 10:37 UTC | |
by Tux (Canon) on Jun 01, 2015 at 13:19 UTC | |
by soonix (Chancellor) on Jun 02, 2015 at 09:38 UTC |