- 论坛徽章:
- 0
|
能够用perl捕捉一个文件的实时变化情况吗?
perldoc -f seek
Due to the rules and rigors of ANSI C, on some systems you have
to do a seek whenever you switch between reading and writing.
Amongst other things, this may have the effect of calling
stdio's clearerr(3). A WHENCE of 1 ("SEEK_CUR" is useful for
not moving the file position:
seek(TEST,0,1);
This is also useful for applications emulating "tail -f". Once
you hit EOF on your read, and then sleep for a while, you might
have to stick in a seek() to reset things. The "seek" doesn't
change the current position, but it *does* clear the end-of-file
condition on the handle, so that the next "<FILE>;" makes Perl
try again to read something. We hope.
If that doesn't work (some IO implementations are particularly
cantankerous), then you may need something more like this:
for (; {
for ($curpos = tell(FILE); $_ = <FILE>;;
$curpos = tell(FILE)) {
# search for some stuff and put it into files
}
sleep($for_a_while);
seek(FILE, $curpos, 0);
} |
|