130*_*nrd 1 perl initialization export-to-csv
我正在尝试使用以下代码将查询结果导出到CSV文件:
while (my $query_result = $query_select->fetchrow_arrayref) {
print $fh join (',', map {s{"}{""}g; "=\"$_\"";} @$query_result), "\n";
}
Run Code Online (Sandbox Code Playgroud)
并得到这些警告:
因为某些记录中有NULL值.
如何在代码中将未定义的值替换为空字符串?
谢谢.
不要试图破解自己的版本,使用正确的CSV模块,就像Text::CSV这样做.例如:
use strict;
use warnings;
use Text::CSV;
my $csv = Text::CSV->new( {
binary => 1,
eol => $/,
} );
...
$csv->print(*STDOUT, $query_result);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
661 次 |
| 最近记录: |