Hello! 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.