perlAffen has asked for the wisdom of the Perl Monks concerning the following question:
$firstrun = 1; while(1) { if ( -s $file ) { sleep 1; open(TF,$file) || next ; seek(TF,0,0); @lines=<TF>; my $curpos=tell(TF); close(TF); if ( $firstrun < 1 ){ foreach $lyne (@lines){ printf $lyne; } } sleep 1; $firstrun = 0; while(-s $file ) { open(TF,$file) || last ; seek(TF,$curpos,0); @lines=<TF>; $curpos = tell(TF); last if ((stat(_))[7] < $curpos); foreach $lyne (@lines){ printf $lyne; } close(TF); sleep 1; } } else { sleep 5; } }
Can anyone help with making the above not read through the whole file, possibly becoming more memory efficient ?while (1) { stat the file if size of file changed since last time { open file seek to previous EOF print file contents until EOF save EOF position for next time close the file } sleep for x seconds }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File::Tail on win32
by GrandFather (Saint) on Nov 29, 2005 at 23:20 UTC | |
by perlAffen (Sexton) on Nov 30, 2005 at 00:47 UTC | |
by perlAffen (Sexton) on Nov 30, 2005 at 01:44 UTC | |
by GrandFather (Saint) on Nov 30, 2005 at 03:26 UTC |