Hi,

I have created a program that monitors a text file which sits on another
computer from the network, and when it sees a change in that file, it opens
it, and gets the newly added lines.
I have seen that the program consumes too many computer resources and I want
to improve it a little.

The program saves (in a temp file) the number of the last line from that
file, and each time it opens the file, it jumps over that number of lines.
I don't know if this is the best way of getting only the new data, but the
real problem is with the main while loop.

I have done something like:

my $exit = 0;
$SIG{INT} = sub {$exit++};

while(!$exit) {
if ([file_was_modified]) {
#process the newly added lines
}
}

The problem is that while the file is not modified, the program doesn't
process any data, so the loop is a kind of while(1) {} loop which consumes
many resources (normally).

I know that I could put the program to sleep for a while, using sleep() or
select() in the while loop, but... is this the only way?

I would like to have a program which stays and waits for a signal or
something, and when the remote file is modified, the program start to
process it, then remains waiting again.

Is this (or something similar) possible?

Thank you.

Teddy


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to