-1
我想使用CSV_XS在.csv文件中读取,然后从标题中选择列以匹配存储在阵列中的内容,然后输出新的.csv使用CSV_XS读取.CSV文件并选择指定的列
use strict;
use warnings;
use Text::CSV_XS;
my $csvparser = Text::CSV_XS->new() or die "".Text::CSV_XS->error_diag();
my $file;
my @headers;
foreach $file (@args){
my @CSVFILE;
my $csvparser = Text::CSV_XS->new() or die "".Text::CSV_XS->error_diag();
for my $line (@csvfileIN) {
$csvparser->parse($line);
my @fields = $csvparser->fields;
$line = $csvparser->combine(@fields);
}
}
您不需要为每个文件创建一个新的'Text :: CSV_XS'对象。 – ThisSuitIsBlackNot 2015-04-02 15:59:37
另外,你能澄清你的意思吗?“在数组中匹配标题?”你是说你只想输出与给定数组中的值匹配的列吗? – ThisSuitIsBlackNot 2015-04-02 16:01:06
对不起,没有任何方式的Perl专家。更新了@ThisSuitIsBlackNot这个问题 – OfficialBenWhite 2015-04-02 16:38:22