Howdy, I am attempting to use a continous for() loop while reading a log file. I then use tell() and seek() to re-establish the last known position within the log file. I works (kinda), but I keep losing my first entry of the log. That is from the first moment it opens the log or if I cat additional information to the log, the first new entry is dropped. Can anyone explain what could be happening. Below is a sample of the code I am using. I have tried different WHENCE values on the seek which doesn't help. And if I drop the for() loop and just print the FH it does print all entries of the log, thus the dropping of the first entry is clearly asscoiated with the loop, but I can not understand where it is going. Thanks for all help, Danny.
#!/usr/bin/perl # # # $LogFile="/usr/local/apache2/eventmgr/ncomount/page.log"; $naptime=3; #Reads LOGFILE continuously open(LOGFILE,"<$LogFile") || die "Couldn't open file Status - $!\n"; for (;;) { for ($logpos = tell(LOGFILE); <LOGFILE>; $logpos = tell(LOGFILE)) { while(<LOGFILE>){ print; } sleep $naptime; seek(LOGFILE, $logpos, 0); # seek to last known } }

20040225 Edit by BazB: Changed title from 'Where did it go???'


In reply to Losing first entry of Apache log by onegative

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.