Dear monks,
I desperately need divine guidance on accomplishing the following:
1. Read and parse through a log file
2. Remember and store the offset to the last line read
3. Next time in, start reading the log file at the previous offset
I believe I am part way there as i've gained some great snippets from the 'hall of records' at the monestery, however i am getting some unexpected results. I can parse through and start at what i believe to be the appropriate offset but I get an extraline or something when it writes to my datafile.
Here is what my code looks like:
# open the log file
open(REGLOG, $regLog) or die "Can't open logfile: $regLog";
#open data file
open(REGDATA, ">> $regDataFile") or die "can't open the Registration d
+ata file";
# seek to last offset
seek(REGLOG, $offset[0], 1);
while (<REGLOG>)
{
chomp; # removing trailing \n
# code truncated here for brevity.....
# fields defined through delimiters....
print REGDATA "$regDate, $regUserName, $regEmail, $regCountry, $re
+gIp, $regRefer, \n";
}
The file begins reading from the offset but adds an extra line of ,,,,,, It is as if it is reading an extra line which I thought chomp would remove. Any ideas what I am missing?? Thanks.
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.