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
現在我想說明,如果該文件已更改,刪除或者是新的。因爲這個,我需要把輸出放入一個變量中。有人能幫我嗎?