Monks,
I'm looking for the most efficient way to repeatedly check a file for a new last-modified date.
I currently have a script which continuously monitors a fast-growing log file for new lines and checks them using some parameters loaded from a config file. As such it uses
(stat(FILE))[7] on the log file to notice new lines and
(stat(FILE))[1) to check for a new inode number when the log gets rotated.
I plan to 'daemonize' this when I get it working and I want to support updating the config file on the fly. To do this I note the modified date in
$lastModConfig when I open it then check as follows:
if( (stat($configFileName))[9] != $lastModConfig ){
...re-process config...
}
However, this can produce a warning about using an undefined value with a not equal comparison if the config file is ever missing (renamed etc.) Of course I could fix this by checking for definedness first with:
if( defined (stat($configFileName))[9] && (stat($configFileName))[9] != $lastModConfig ){
...re-process config...
}
but then I'd be calling stat twice. Since this check happens every couple of seconds (remember the log file grows fast) I don't want to eat up any cycles I don't have to.
Is there a better (less CPU time) way to pre-check the file for existance than calling
stat($configFileName) or is the an altogether better way to check for modifications to the config file?
Perhaps I should just accept an extra second or two of CPU time every hour to do the second check. Or am I being entirely too neurotic about the warnings? They are just warnings after all and the script functions as intended.
I could, of course, just throw in a
no warnings 'uninitialized'; or even let the warnings drop into the void since STDERR will go to null when this script is a daemon.
I'd like to know what course those with more experience would take.
Thanks,
Cefu
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.