为什么 DBD::CSV 抱怨“松散的未转义引号”?
为什么从 __DATA__ 读取有效,而从文件读取无效(松散的未转义引号)?
#!/usr/bin/env perl
use warnings; use strict; use 5.010;
use DBI;
my $table = 'klassik_CD.csv';
print qx(cat $table);
print qq{\n"data" or "Enter" : };
chomp( my $aw = <> );
if ( $aw eq 'data' ) {
$table = 'te_mp_fi_le.csv';
open my $fh, '>', $table or die $!;
while ( defined( my $row = <DATA> ) ) {
print $fh $row;
}
close $fh or die $!;
}
my $dbh = DBI->connect( "dbi:CSV:", { RaiseError => 1 } );
$dbh->{csv_tables}{$table} = { col_names => [], sep_char => ';' };
my $sth = $dbh->prepare( "SELECT * FROM $table" );
$sth->execute;
while ( defined( my $row = $sth->fetchrow_hashref ) ) {
say $row->{col1};
}
__DATA__
1;"Kammermusik fuer Blaeser";16;"DG";"eloquence";"dc129610"
2;"Requiem – Laudate Dominum Exultate, jubilate";19;"DG";"eloquence";"0a11f513"
输出:“数据”
1;"Kammermusik fuer Blaeser";16;"DG";"口才";"dc129610"
2;“安魂曲 – Laudate Dominum 狂喜,欢呼”;19;“DG”;“雄辩”;“0a11f513”
“数据”或“输入”:数据
Blaeser 室内音乐
安魂曲 – Laudate Dominum 狂喜、欢呼
输出:“Enter”
1;"Kammermusik fuer Blaeser";16;"DG";"口才";"dc129610"
2;“安魂曲 – Laudate Dominum 狂喜,欢呼”;19;“DG”;“雄辩”;“0a11f513”
“数据”或“输入”:
DBD::CSV::st 执行失败:
执行错误:读取文件 ./klassik_CD.csv 时出现错误 2034:EIF - /usr/local/lib/perl5/site_perl/5.10.1/DBD/CSV.pm 第 220 行处的松散未转义引号
。
[for 语句“SELECT * FROM klassik_CD.csv”]位于 ./zzzzzzzzzz.pl 第 27 行。
DBD::CSV::st fetchrow_hashref 失败:尝试在没有先前的execute ()调用的情况下或从非SELECT语句[for语句“SELECT * FROM klassik_CD.csv”]在./zzzzzzzzzz.pl第28行获取行。
Why does reading from __DATA__ work and reading from the file doesn't (Loose unescaped quote)?
#!/usr/bin/env perl
use warnings; use strict; use 5.010;
use DBI;
my $table = 'klassik_CD.csv';
print qx(cat $table);
print qq{\n"data" or "Enter" : };
chomp( my $aw = <> );
if ( $aw eq 'data' ) {
$table = 'te_mp_fi_le.csv';
open my $fh, '>', $table or die $!;
while ( defined( my $row = <DATA> ) ) {
print $fh $row;
}
close $fh or die $!;
}
my $dbh = DBI->connect( "dbi:CSV:", { RaiseError => 1 } );
$dbh->{csv_tables}{$table} = { col_names => [], sep_char => ';' };
my $sth = $dbh->prepare( "SELECT * FROM $table" );
$sth->execute;
while ( defined( my $row = $sth->fetchrow_hashref ) ) {
say $row->{col1};
}
__DATA__
1;"Kammermusik fuer Blaeser";16;"DG";"eloquence";"dc129610"
2;"Requiem – Laudate Dominum Exultate, jubilate";19;"DG";"eloquence";"0a11f513"
Output: "data"
1;"Kammermusik fuer Blaeser";16;"DG";"eloquence";"dc129610"
2;"Requiem – Laudate Dominum Exultate, jubilate";19;"DG";"eloquence";"0a11f513"
"data" or "Enter" : data
Kammermusik fuer Blaeser
Requiem – Laudate Dominum Exultate, jubilate
Output: "Enter"
1;"Kammermusik fuer Blaeser";16;"DG";"eloquence";"dc129610"
2;"Requiem – Laudate Dominum Exultate, jubilate";19;"DG";"eloquence";"0a11f513"
"data" or "Enter" :
DBD::CSV::st execute failed:
Execution ERROR: Error 2034 while reading file ./klassik_CD.csv: EIF - Loose unescaped quote at /usr/local/lib/perl5/site_perl/5.10.1/DBD/CSV.pm line 220
.
[for Statement "SELECT * FROM klassik_CD.csv"] at ./zzzzzzzzzz.pl line 27.
DBD::CSV::st fetchrow_hashref failed: Attempt to fetch row without a preceeding execute () call or from a non-SELECT statement [for Statement "SELECT * FROM klassik_CD.csv"] at ./zzzzzzzzzz.pl line 28.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我将文件从“klassik_CD.csv”重命名为“klassik_cd.csv”(全部小写)时,它可以工作(尽管没有“文件未找到”之类的消息)。
When I rename the file from "klassik_CD.csv" to "klassik_cd.csv" (all lowercase) it works (though there was no such message as "file not found" ).