M
Mark
(I don't seem to be able to prohibit the data portion below from
line-wrapping -- Sorry!)
Below is a Perl script followed by the data it is reading (to be in a
file called "./data/location". The data portion has a line used as
column headings, followed by 10 lines of data. The 9th line of data has
some double quotes in one of the fields. This ceases the reading of the
data at line 8. I have no idea why. I tried adding csv_escape => '"'
and csv_quote => '"' to the connect function, but these seem to have no
effect. If I remove the quote from the file, all 10 lines are read and
printed. In fact, all 11,000 lines of the full-length version of
location will be read in and printed, but the quotes halt it wherever
they are encountered. I'm stupified! Please offer helpful suggestions
in this regard. (DBD::CSV 0.22) (SQL::Statement 1.14), and
(Text::CSV_XS 0.23)
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,RaiseError => 1,
csv_eol => "\n",csv_sep_char => '|'}
);
my $sql = "SELECT * FROM location ORDER BY lid";
my $sth = $dbh->prepare("$sql");
if(defined($sth)) {
$sth->execute();
}
my $data = $sth->fetchall_arrayref;
$sth->finish();
$dbh->disconnect();
if(defined $data) {
print "\$data is defined. Number of records = " .
scalar @$data . "\n"; }
else { print "\$data is undefined\n"; }
my $i = 0;
foreach (@$data) {
print "$i: " . (join ', ',@$_) . "\n";
$i++;
}
exit;
__END__
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||LOT||41.9844444444444|88.0980555555556|||Chicago/Schaumburg|Unk||Unk|||IL||LOT|||||1||CST6CDT
GNCK2|Gallatin|||at|0||ILN||38.705|84.8238888888889|Eagle
Creek|2005-03-02|Glencoe|Unk|Ohio River
(OHL)|OHRFC|||KY||ILN|||GLENCOE|Eagle Creek|1|3000|EST5EDT
WNSI2|Shelby|||7
SE|0||ILX||39.3594444444444|88.5058333333333||2005-05-11|Windsor|Unk|Little
Wabash (LWA)|OHRFC|||IL||ILX|||WINDSOR 7SE||1|9000|CST6CDT
LNBO1|Washington|||at|0||RLX||39.5630555555556|81.2038888888889|Little
Muskingum River at Bloomfield, OH.||Bloomfield|Unk|Huntington Segment -
Ohio|OHRFC|||OH||RLX|||Bloomfield||1||EST5EDT
07S|Unk|||at|||Unk||47.9667|117.433||||Unk||Unk|||XX||Unk|||||0|ASOS|EST5EDT
CLE1412|Ashtabula||||||CLE||41.53|80.53|PAUL MECHLING,
440-577-1111||PIERPONT 2SE|Unk||OHRFC|||OH||CLE|||||1||EST5EDT
CLE1414|Ashtabula||||||CLE||41.85|80.8|COOP,
n/a||ASHTABULA|Unk||OHRFC|||OH||CLE|||||1||EST5EDT
CLE1415|Ashtabula||||||CLE||41.68|80.67|COOP,
n/a||DORSET|Unk||OHRFC|||OH||CLE|||||1||EST5EDT
OPKW2|Monongalia|||1
N|860||PBZ||39.5644444444444|80.0491666666667|Monongahela River at
Opekiska Lock|2005-02-10|Opekiska|Unk|Monongahela
River|OHRFC|||WV||PBZ|||OPEKISKA 1N|39d33'52" -80d02'57"|1|3000|EST5EDT
22G|Unk|||at|0||CLE||41.3441666666667|82.1777777777778|||Lorain/Elyria|Unk||OHRFC|||OH||CLE|||||1|ASOS|EST5EDT
line-wrapping -- Sorry!)
Below is a Perl script followed by the data it is reading (to be in a
file called "./data/location". The data portion has a line used as
column headings, followed by 10 lines of data. The 9th line of data has
some double quotes in one of the fields. This ceases the reading of the
data at line 8. I have no idea why. I tried adding csv_escape => '"'
and csv_quote => '"' to the connect function, but these seem to have no
effect. If I remove the quote from the file, all 10 lines are read and
printed. In fact, all 11,000 lines of the full-length version of
location will be read in and printed, but the quotes halt it wherever
they are encountered. I'm stupified! Please offer helpful suggestions
in this regard. (DBD::CSV 0.22) (SQL::Statement 1.14), and
(Text::CSV_XS 0.23)
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,RaiseError => 1,
csv_eol => "\n",csv_sep_char => '|'}
);
my $sql = "SELECT * FROM location ORDER BY lid";
my $sth = $dbh->prepare("$sql");
if(defined($sth)) {
$sth->execute();
}
my $data = $sth->fetchall_arrayref;
$sth->finish();
$dbh->disconnect();
if(defined $data) {
print "\$data is defined. Number of records = " .
scalar @$data . "\n"; }
else { print "\$data is undefined\n"; }
my $i = 0;
foreach (@$data) {
print "$i: " . (join ', ',@$_) . "\n";
$i++;
}
exit;
__END__
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||LOT||41.9844444444444|88.0980555555556|||Chicago/Schaumburg|Unk||Unk|||IL||LOT|||||1||CST6CDT
GNCK2|Gallatin|||at|0||ILN||38.705|84.8238888888889|Eagle
Creek|2005-03-02|Glencoe|Unk|Ohio River
(OHL)|OHRFC|||KY||ILN|||GLENCOE|Eagle Creek|1|3000|EST5EDT
WNSI2|Shelby|||7
SE|0||ILX||39.3594444444444|88.5058333333333||2005-05-11|Windsor|Unk|Little
Wabash (LWA)|OHRFC|||IL||ILX|||WINDSOR 7SE||1|9000|CST6CDT
LNBO1|Washington|||at|0||RLX||39.5630555555556|81.2038888888889|Little
Muskingum River at Bloomfield, OH.||Bloomfield|Unk|Huntington Segment -
Ohio|OHRFC|||OH||RLX|||Bloomfield||1||EST5EDT
07S|Unk|||at|||Unk||47.9667|117.433||||Unk||Unk|||XX||Unk|||||0|ASOS|EST5EDT
CLE1412|Ashtabula||||||CLE||41.53|80.53|PAUL MECHLING,
440-577-1111||PIERPONT 2SE|Unk||OHRFC|||OH||CLE|||||1||EST5EDT
CLE1414|Ashtabula||||||CLE||41.85|80.8|COOP,
n/a||ASHTABULA|Unk||OHRFC|||OH||CLE|||||1||EST5EDT
CLE1415|Ashtabula||||||CLE||41.68|80.67|COOP,
n/a||DORSET|Unk||OHRFC|||OH||CLE|||||1||EST5EDT
OPKW2|Monongalia|||1
N|860||PBZ||39.5644444444444|80.0491666666667|Monongahela River at
Opekiska Lock|2005-02-10|Opekiska|Unk|Monongahela
River|OHRFC|||WV||PBZ|||OPEKISKA 1N|39d33'52" -80d02'57"|1|3000|EST5EDT
22G|Unk|||at|0||CLE||41.3441666666667|82.1777777777778|||Lorain/Elyria|Unk||OHRFC|||OH||CLE|||||1|ASOS|EST5EDT