跳到文件头。 seek FH, 0, 0
跳到文件尾: seek FH,0, 2
判断是否到达文件尾部: if(eof(FH)).
给加分不?#compare folders
use strict
sub get
sub FolderCompare
#输入的格式为:"perl foldercompare.pl <ul1 name><ul2 name>\n"
if ( @ARGV <2 )
{
die
}
system"svn export @ARGV[0] A"
system"svn export @ARGV[1] B"
my $dirA = "A"
my $dirB = "B"
FolderCompare($dirA, $dirB, "0") #第一次正老睁向比较
FolderCompare($dirB, $dirA, "1") #第二次反向比较,主要是查出B中有而A中没有的
#其中第三个侍卖岁参数是为了清除第一次已经输出的不一样的文本
system"rm A -rf"
system"rm B -rf"配磨
print "Finished!"
sub get
{
my $dir = $_[0]
my %array
opendir(DIR, $dir)
while (my $file = readdir(DIR))
{
my @array_tmp = stat("$dir/$file")
if($file =~ m/^[^.]/)
{
if(-d "$dir\\$file") #判断是否为目录,并标记
{
$array{$file} = [$array_tmp[7], "1"]
}
if(-f "$dir\\$file") #判断是否为文件,并标记
{
$array{$file} = [$array_tmp[7], "0"]
#print "$file\t$array{$file}[1]\n"
}
}
}
return %array
}
sub FolderCompare
{
my $FolderA = $_[0]
my $FolderB = $_[1]
my $temp = $_[2]
my %arrayA = get($FolderA)
my %arrayB = get($FolderB)
foreach my $FileNameA (keys(%arrayA))
{
if(exists($arrayB{$FileNameA}))
{
if($arrayA{$FileNameA}[1] eq "1")
{
if($arrayB{$FileNameA}[1] eq "1")
{
FolderCompare("$FolderA\\$FileNameA", "$FolderB\\$FileNameA", "$temp") #都为目录,进行递归
}
}
if($arrayA{$FileNameA}[1] eq "0") #都为文件,进行比较
{
if($arrayB{$FileNameA}[1] eq "0")
{
if($arrayA{$FileNameA}[0] != $arrayB{$FileNameA}[0])
{
if($temp == 0)
{
print "$FolderA\\$FileNameA is different from $FolderB\\$FileNameA\n"
}
}
}
}
}
else
{
print "$FolderA\\$FileNameA is not exitst in $FolderB\n"
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)