【发布时间】:2012-06-28 19:36:27
【问题描述】:
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 将包含文件的名称,后跟换行符,因此 open 将失败,因此它会死。
chomp可以解决这个问题。还有许多其他问题,但是评论不是你的代码的东西有什么意义呢?我强烈建议您首先添加use strict; use warnings;并修复这些错误。 -
它有文件,如您所见,它在第一行打印为“archive/oswiostat/oracleapps.localdomain_iostat_12.06.28.1500.dat”
-
不,它有
"archive/oswiostat/oracleapps.localdomain_iostat_12.06.28.1500.dat\n" -
@ikegami,这是实际代码。在我的Linux系统上,根据strace,
open(F, "newline\n")调用open("newline" *[sic]*, ...),但stat "newline\n"调用stat("newline\n" *[sic]*, ...)。你是对的,这是换行的麻烦。三参数 open 似乎保留了换行符 FWIW。 -
那么解决方法是什么?
标签: perl filesystems change-notification