原帖由 mantou 于 2008-4-26 21:50 发表
DBD::CSV
不知道该如何来用。 首先需要将csv导入生成一个table。那么,第一行怎么办?
我现在已经通过常规数组的方法可以合并。但总感觉对于csv这种格式化的数据,采用土办法不是很明智。
use strict; use warnings; use Text::CSV_xs; ###### combine two csv records ####### my @files=<*.csv>; my $count=-1; open(OUT,">>end.csv"); foreach my $table(0..$#files) { my $csv = Text::CSV_XS->new ({ binary => 1 , blank_is_undef => 1}); open my $fh, "<", "$files[$table]" or die ": $!"; while (my $row = $csv->getline ($fh)) { if($table < 1) { $count++; print OUT join(',',@$row ); print OUT "\n"; } else{ if( $$row[0] =~ /sn/) { next; } else{ $$row[0]=$count+1; print OUT join(',',@$row ); print OUT "\n"; $count++; } } } close $fh; } print "\nALL Records: ".$count."\n"; close(OUT); |
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |