在这个脚本中,我遇到了文件名扩展的问题:如果我使用 /home/mm/test_x 它可以工作,而文件名为 /home/mm/test_x.csv 它不会:
#!/usr/bin/env perl
use warnings; use strict;
use 5.012;
use DBI;
my $table_1 = '/home/mm/test_1.csv';
my $table_2 = '/home/mm/test_2.csv';
#$table_1 = '/home/mm/test_1';
#$table_2 = '/home/mm/test_2';
my $dbh = DBI->connect( "DBI:CSV:" );
$dbh->{RaiseError} = 1;
$table_1 = $dbh->quote_identifier( $table_1 );
$table_2 = $dbh->quote_identifier( $table_2 );
my $sth = $dbh->prepare( "SELECT a.id, a.name, b.city FROM $table_1 AS a NATURAL JOIN $table_2 AS b" );
$sth->execute;
$sth->dump_results;
$dbh->disconnect;
带有文件名扩展的输出:
DBD::CSV::st 执行失败:
执行错误:没有从 /usr/local/lib/perl5/site_perl/5.12.0/x86_64-linux 调用的列 '"/home/mm/test_1.csv".id' /DBD/File.pm 在 570。
没有文件扩展名的输出:
'1'、'Brown'、'Laramie'
'2'、'Smith'、'Watertown'
2 行
这是一个错误吗?
猫 test_1.csv
id,姓名
1,棕色
2,史密斯
5,绿色
猫 test_2.csv
id,city
1,Laramie
2,Watertown
8,Springville