slogger has asked for the wisdom of the Perl Monks concerning the following question:

Hi - first post here :-) I want to read a file thats changing and print the line within that file thats changing - the file isnt being appended to but the lines within the file are changing (hope thats clear!)

I wrote a perl script - works which is good, however as I'm learning perl I'm sure theres a better way of doing this - essentially I'm using a loop, opening file, reading line, extracting data from line, closing file, then sleeping 10 secs then repeating.. instead of doing numerous open/close what would people suggest - I've thought maybe opening, reading then seeking back to start - however that didnt seem to pick updates..

ideas welcome!numpty code follows:-

#!/usr/bin/perl -w # program to print out cumulative interrupt for network device drivers use strict; #use diagnostics; while (1) { open(PFS,"/proc/interrupts")||die "Cant open file $! \n"; while (<PFS>) { if ( $_ =~ "eth" ) { # change print format here .. overlay and have headers print $_; } # seek(PFS,0,1); # print tell PFS; } close(PFS); sleep(10); }
Thanks Slogger.

Replies are listed 'Best First'.