Perl FAQ 5.22: How do I do a "tail -f" in Perl?

Perl FAQ 5.22

How do I do a "tail -f" in Perl?

Larry says that the solution is to put a call to seek in yourself. First try

        seek(GWFILE, 0, 1);

The statement seek(GWFILE, 0, 1); doesn't change the current position, but it does clear the end-of-file condition on the handle, so that the next makes Perl try again to read something.

If that doesn't work (depends on your stdio implementation), then you need something more like this:

    for (;;) {
	for ($curpos = tell(GWFILE); $_ = ; $curpos = tell(GWFILE)) {
	    # search for some stuff and put it into files
	}
	sleep for a while
	seek(GWFILE, $curpos, 0);
    }

Other resources at this site: