加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl比较两个目录中的文件内容是否相同

发布时间:2020-12-16 00:07:08 所属栏目:大数据 来源:网络整理
导读:#比较两个目录中的文件内容是否相同 #!/bin/perl if($#ARGV 0) { ?print "usage:perl compare.pl dir1 dir2n"; ?exit(-1); } #my($rec,$ref) = @ARGV; #!/bin/perl my($lat1,$lat2)=@ARGV; system ( "dir /b /s /O:N? $lat1*.lat lat1.list "); syst

#比较两个目录中的文件内容是否相同
#!/bin/perl
if($#ARGV < 0)
{
?print "usage:perl compare.pl dir1 dir2n";
?exit(-1);
}
#my($rec,$ref) = @ARGV;

#!/bin/perl

my($lat1,$lat2)=@ARGV;

system ( "dir /b /s /O:N? $lat1*.lat > lat1.list ");
system ( "dir /b /s /O:N? $lat2*.lat > lat2.list ");

my $dif=1;

open(dlat1,"<lat1.list") or die "3n";
open(dlat2,"<lat2.list") or die "4n";
open(result,">result.log") or die "5n";
$old = select result;
$|=1;?? #immediately write flush(result);
select $old;


??my @alat1 = ();
??? my @alat2 = ();
@alat1 = <dlat1>;
@alat2 = <dlat2>;
my $countout=@alat2;
my $count=0;
my $count2=0;
#select (select (result),$|=1)[0];
print (result? "result isn");
?$|++;? # perl中的flush缓冲区?? flush($tmp);
#close(result);
?
?
??? for my $latline1 (@alat1)
??? {
?#?? ?open(result,">>result.log") or die "6n";
???? chomp $latline1;
???? $count2=0;
????
???? for my $latline2 (@alat2)
???? {
???? ?chomp $latline2;
???? ?$dif = &find_fileindir("$latline1","$latline2");
???? ?#$count2++;
???? ?#print "$count:$count2 :dif is $difn" ;
???? ?if($dif==0)
???? ?{
???? ??print (result? "$latline1 is equal $latline2n");
???? ?? $|++;? # perl中的flush缓冲区?? flush($tmp);
???? ??#system ( "del /f /q? $latline2");
???? ??
???? ??
???? ??last;
???? ?}
???? ?if($dif==1)
???? ?{
???? ??$count2++;
???? ?}
???? ?print "$count:$count2 :dif is $difn" ;
???? }
???? #print "count2 is $count2n";
???? #print "countout is $countoutn";
???? if ($count2>=$countout)
???? {
???? ?print (result "$latline1 is not foundn");
???? ? $|++;? # perl中的flush缓冲区?? flush($tmp);
???? }
?#??? close(result);
???? $count++;
???? #print "$countn";
????
?? }

#$dif=&find_fileindir("$rec","$ref");

#print "dif is $dif";
close (dlat1);
close (dlat2);
close (result);

#下面函数比较两个文件的内容是否相同
sub find_fileindir()
{
?
?local ($rec1,$ref1) = @_;

open(A,"$rec1") or die "1n";
open(B,"$ref1") or die "2n";
#open A,"a.txt";
#open B,"b.txt";
local @a=<A>;
local @b=<B>;
@a=map{split(/s+/,$_)}@a;
#@a=map split @a;
@b=map{split(/s+/,$_)}@b;
#@b=map split @b;
local $a=@a;
local $b=@b; local $diff=0;? #0代表相同,1代表不同 if($a<$b) { ?$a=$b; } for (0..$a-1) { ?if ($a[$_]==$b[$_]) ?{ next;} ?else ?{ $diff=1;return "$diff";} } #print "$diffn"; return "$diff"; close(A); close(B); }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读