0
我得到以下功能,并不知道如何将输出放入一个变量。比较文件和打印差异使用打印,除非
sub checkFiles {
# Declaration
my $origDir="/home/hbo/test/chksum/";
my $tmpDir="/home/hbo/test/tmp/";
# get directory inventory
opendir(DIR, $origDir);
my @files = sort (grep { !/^\.|\.\.}$/ } readdir(DIR));
closedir(DIR);
foreach my $file (@files) {
if (!-r $origDir.$file) { print $origDir.$file, "does not exist"; next;}
# open filehandles
open my $a_fh, '<', $origDir.$file or die "$origDir.$file: $!";
open my $b_fh, '<', $tmpDir.$file or die "$tmpDir.$file: $!";
# map difference
my %tmpDirFile;
@tmpDirFile{map { unpack 'A*', $_ } <$b_fh>} =();
# print difference
while (<$a_fh>) {
print unless exists $tmpDirFile{unpack 'A*', $_};
}
close $a_fh;
close $b_fh;
}
}
我得到了问题的行是 “打印,除非存在$ {tmpDirFile解包 'A *',$ _};”我想把这个输出放入一个像数组这样的变量中,我可以在“更改”或“删除”或“新”之间做出决定。一个简短的总结我的脚本将做的事情:它构建一个目录的md5总和,检查目录是否与之前的版本不同,并用“新”,“删除”,“更改”等标志打印差异。是的,我不想使用额外的库。
在控制台上的输出是:
40567504a8a2f9f665695a49035b381b /home/hbo/test/somedir/some/some.conf
现在我想说明,如果该文件已更改,删除或者是新的。因为这个,我需要把输出放入一个变量中。有人能帮我吗?