用于比较两个文件不同的行差集
发布时间:2020-12-15 21:10:13 所属栏目:大数据 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #!/usr/bin/perl -wuse strict;my ($fileA,$fileB) = @ARGV;open A,'',$fileA or die "Unable to open file:$fileA:$!";my %ta;my $i; while(A){ chom
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 #!/usr/bin/perl -w use strict; my ($fileA,$fileB) = @ARGV; open A,'<',$fileA or die "Unable to open file:$fileA:$!"; my %ta; my $i; while(<A>){ chomp; $ta{$_} = ++$i; } close A; open B,$fileB or die "Unable to open file:$fileB:$!"; my @B; while(<B>){ chomp; unless (defined $ta{$_}){ push @B,$_; }else{ $ta{$_} = 0; } } close B; # Output diff to different files respectively open DIFF_A,">$fileA.diff" or die "Unable to create diff file for $fileA:$!"; my $countA; print "Remain in files $fileAn"; my %tt = reverse %ta; foreach (keys %tt) { $countA += $_>0? print DIFF_A $tt{$_}."n":0; } print "$countA linesn"; close DIFF_A; open DIFF_B,">$fileB.diff" or die "Unable to create diff file for $fileB:$!"; my $countB = scalar @B; print DIFF_B $_."n" foreach @B; if ($countA == 0 and $countB ==0 ){ print STDOUT "The two files are identicaln"; } close DIFF_B; 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |