use Text::Diff;
for($count = 0; $count <= 1000; $count++){
my $data_dir="archive/oswiostat/oracleapps.*dat";
my $data_file= `ls -t $data_dir | head -1`;
while($data_file){
print $data_file;
open (DAT,$data_file) || die("Could not open file! $!");
$stats1 = (stat $data_file)[9];
print "Stats: \n";
@raw_data=<DAT>;
close(DAT);
print "Stats1 is :$stats1\n";
sleep(5);
if($stats1 != $stats2){
@diff = diff \@raw_data, $data_file, { STYLE => "Context" };
$stats2 = $stats1;
}
print @diff || die ("Didn't see any updates $!");
}
}
$ perl client_socket.pl
archive/oswiostat/oracleapps.localdomain_iostat_12.06.28.1500.dat
Stats:
Stats1 is :
Didn't see any updates at client_socket.pl line 18.
你能告訴我,爲什麼統計數據缺失,以及如何解決它?
我不相信那是你實際運行的代碼。 $ data_file將包含文件的名稱後跟一個換行符,所以打開會失敗,所以它會死。 chomp會解決這個問題。還有很多其他的問題,但對那些不是你的代碼的東西有什麼意見?我強烈建議你先加入'use strict;使用警告;'並修復這些錯誤。 – ikegami
它有文件,因爲你看它打印在第一行爲「archive/oswiostat/oracleapps.localdomain_iostat_12.06.28.1500.dat」 – VeerM
不,它有'「archive/oswiostat/oracleapps.localdomain_iostat_12.06.28.1500.dat \ n「' – ikegami