M
Mark
On the DBD::CSV doc page at CPAN.org, I am referred to two links at the
end of it for further support. Both links give me a 404 page.
I'm running into a problem with CSV in that it is not pulling data from
a file. Below is my code, a "head" of my data (in the file
"data/location"), and the error message I get (the first one indicates a
possible secondary problem in that $sth->errstr is not set even though
an error is detected).
I have experience using DBI for other code involving databases such as
PostgreSQL and Informix, but this problem with CSV is perplexing me.
I've tried putting .csv suffix on my file, and replaced all semicolons
with commas, too. But none of this seems to matter.
Anyone have any ideas??
Mark
___________________________________________
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbstr = 'DBI:CSV:f_dir=data';
my $dbh = DBI->connect($dbstr,undef,undef,{ChopBlanks => 1,PrintWarn =>
1,PrintError => 0}) or warn "Cannot connect to: $dbstr: " .
DBI->errstr;
my $sql = "SELECT * FROM location ORDER BY lid;";
my $sth = $dbh->prepare("$sql") or die "Cannot prepare SQL: $sql -- " .
$dbh->errstr;
if(defined($sth)) {
$sth->execute() or warn "Unable to execute on $dbstr: $sql -- "
. $sth->errstr; # this execute statement is line 13 ...
# ... that causes the error
}
exit;
__END__
[oper@na_dell7-tir scripts]$ head data/location
lid;county;coe;cpm;detail;elev;hdatum;hsa;hu;lat;lon;lremark;lrevise;name;network;rb;rfc;sbd;sn;state;waro;wfo;wsfo;type;des;det;post;stntype;tzone
06C;Unk;;;at;0.0;;LOT;;41.9844444444444;88.0980555555556;;;Chicago/Schaumburg;Unk;;Unk;;;IL;;LOT;;;;;1;;CST6CDT
07S;Unk;;;at;;;Unk;;47.9667;117.433;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
0A6;Unk;;;at;;;Unk;;35.2;81.15000000000002;;;;Unk;;SERFC;;;XX;;Unk;;;;;0;ASOS;EST5EDT
0V1;Unk;;;at;;;Unk;;43.7333;103.617;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
0Y7;Unk;;;at;;;Unk;;40.6333;93.90000000000001;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
0Z0;Unk;;;at;;;Unk;;66.0667;162.767;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
12N;Unk;;;at;;;Unk;;41.0167;74.7333;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
14G;Unk;;;at;0.0;;CLE;;41.33333333333334;83.16111111111111;;;Fremont;Unk;;OHRFC;;;OH;;CLE;;;;;1;;EST5EDT
[oper@na_dell7-tir scripts]$ ./testcase.pl
Use of uninitialized value in concatenation (.) or string at
../testcase.pl line 13.
Unable to execute on DBI:CSV:f_dir=data: SELECT * FROM location ORDER BY
lid; -- at ./testcase.pl line 13.
end of it for further support. Both links give me a 404 page.
I'm running into a problem with CSV in that it is not pulling data from
a file. Below is my code, a "head" of my data (in the file
"data/location"), and the error message I get (the first one indicates a
possible secondary problem in that $sth->errstr is not set even though
an error is detected).
I have experience using DBI for other code involving databases such as
PostgreSQL and Informix, but this problem with CSV is perplexing me.
I've tried putting .csv suffix on my file, and replaced all semicolons
with commas, too. But none of this seems to matter.
Anyone have any ideas??
Mark
___________________________________________
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbstr = 'DBI:CSV:f_dir=data';
my $dbh = DBI->connect($dbstr,undef,undef,{ChopBlanks => 1,PrintWarn =>
1,PrintError => 0}) or warn "Cannot connect to: $dbstr: " .
DBI->errstr;
my $sql = "SELECT * FROM location ORDER BY lid;";
my $sth = $dbh->prepare("$sql") or die "Cannot prepare SQL: $sql -- " .
$dbh->errstr;
if(defined($sth)) {
$sth->execute() or warn "Unable to execute on $dbstr: $sql -- "
. $sth->errstr; # this execute statement is line 13 ...
# ... that causes the error
}
exit;
__END__
[oper@na_dell7-tir scripts]$ head data/location
lid;county;coe;cpm;detail;elev;hdatum;hsa;hu;lat;lon;lremark;lrevise;name;network;rb;rfc;sbd;sn;state;waro;wfo;wsfo;type;des;det;post;stntype;tzone
06C;Unk;;;at;0.0;;LOT;;41.9844444444444;88.0980555555556;;;Chicago/Schaumburg;Unk;;Unk;;;IL;;LOT;;;;;1;;CST6CDT
07S;Unk;;;at;;;Unk;;47.9667;117.433;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
0A6;Unk;;;at;;;Unk;;35.2;81.15000000000002;;;;Unk;;SERFC;;;XX;;Unk;;;;;0;ASOS;EST5EDT
0V1;Unk;;;at;;;Unk;;43.7333;103.617;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
0Y7;Unk;;;at;;;Unk;;40.6333;93.90000000000001;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
0Z0;Unk;;;at;;;Unk;;66.0667;162.767;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
12N;Unk;;;at;;;Unk;;41.0167;74.7333;;;;Unk;;Unk;;;XX;;Unk;;;;;0;ASOS;EST5EDT
14G;Unk;;;at;0.0;;CLE;;41.33333333333334;83.16111111111111;;;Fremont;Unk;;OHRFC;;;OH;;CLE;;;;;1;;EST5EDT
[oper@na_dell7-tir scripts]$ ./testcase.pl
Use of uninitialized value in concatenation (.) or string at
../testcase.pl line 13.
Unable to execute on DBI:CSV:f_dir=data: SELECT * FROM location ORDER BY
lid; -- at ./testcase.pl line 13.