- 论坛徽章:
- 0
|
本帖最后由 scrit 于 2010-09-26 17:31 编辑
我现在要比较两个CSV文件,我是利用Text::CSV_XS模块来比较的 我的代码如下- #!/usr/bin/perl
- use Text::CSV_XS;
- my $csvfile="file1.csv";
- my $newfile="file2.csv";
- open $old, "<", $csvfile;
- open $new, "<", $newfile;
- open DIFF, ">", "diff.txt";
- my $csvold = Text::CSV_XS->new ({ binary => 1, eol => $/ });
- my $csvnew = Text::CSV_XS->new ({ binary => 1, eol => $/ });
- my $count=0;
- while(my $rowold=$csvold->getline($old))
- {
- my @item1 = @$rowold;
- my @item2;
- my @tt;
- my $line2;
- my @t = @item1;
- my $line = shift @item1;
- $line = shift @item1;
- # print DIFF "$line\t";
- while(my $rownew=$csvnew->getline($new))
- {
- @item2 = @$rownew;
- @tt = @item2;
- $line2 = shift @item2;
- $line2 = shift @item2;
- # print DIFF "$line2\n";
- if($line == $line2)
- {
- $count=$count + 1;
- @t="";
- $line="";
- last;
- }
- }
- if($line =~ /^\w+/)
- {
- print DIFF "@t\n";
- }
- }
复制代码 我的要比较的两个文件在附件里
我是根据CSV文件中的第二列数据进行比较 把FILE1中有的,而FILE2中没有的行提取出来,但是始终不能做到 有没有高人帮我解答下啊?谢谢啦 |
|