Claude" <[EMAIL PROTECTED]> wrote: > > I am reading continuously a file like this: > > open LOG, "junk.txt" or die "Cannot open $file, $!\n"; > while ( my $line = <LOG> ) { > print "$line"; > } > > While appending lines to the file from a shell command line: > > $ echo "this is a new line" >> junk.txt > > Everything ok, except that I would like to find out from the Perl code > above when junk.txt has been deleted, or renamed. Unfortunately, "tail > -f" does not exit... > > Any idea how to do that?
Hi Claude, You need to close and reopen the file if you want to check for a rename. Something like the program below. HTH, Rob use strict; use warnings; use IO::Handle; autoflush STDOUT; use Fcntl qw(:seek); my $file = 'junk.txt'; my $pos; while (1) { open LOG, $file or die "Cannot open $file, $!"; seek LOG, $pos, SEEK_SET if defined $pos; print while <LOG>; $pos = tell LOG; close LOG; sleep 1; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>