Hello Monks,
I seek guidance on what could potentially be a very easy problem to solve. I have a program that writes an output log to a standard text file on a Win32 machine. I'm looking for a way to parse the newest lines added to that log in real-time (new lines added every 100ms - 20s depending). Each log line contains a unique key, so detecting a new and different line should be simple. So I would need some kind of continuous hold/loop waiting for either changes to the log file, or specifically new lines added, etc. My script would then perform an action based on whether or not a couple of pieces of info are found in the new line of the log file.
Simply reading a text file is simple, looking for new lines is simple, parsing the information out is relatively simple, but the log files tend to grow rather large (>1MB) and re-reading the entire log file every X ms interval seems like a huge waste of resources. I don't know why but the brute force read the entire log over and over method comes to mind first and it feels wrong :/
Is there a simpler, more elegant, more perl method to do this? I am relatively new to perl but not new to programming.
Thank you for any advice.
-Alan
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.