http://qs321.pair.com?node_id=464298


in reply to Reopen file when contents changed?

You may simply want seek. I'm not really sure if it is well suited for that particular file, which may not be the case. It' worth trying in any case.

Incidentally under *NIX there's not strictly speaking anything like "text mode".

Update: I didn't want to test this myself, but in the end I did and it seems to work just fine:

#!/usr/bin/perl use strict; use warnings; open my $fh, '<', '/proc/stat' or die $!; { print scalar <$fh>; seek $fh, 0, 0; sleep 1; redo; } __END__

Replies are listed 'Best First'.
Re^2: Reopen file when contents changed?
by dReKurCe (Scribe) on Jun 07, 2005 at 21:15 UTC
    That code worked for me and generated output has follows:
    cpu 757611 0 128970 6183389 cpu 757611 0 128970 6183507 cpu 757611 0 128970 6183608 cpu 757612 0 128970 6183708 cpu 757612 0 128970 6183809