I was testing that theory and it is in fact what is happening. The modified code below works and does not drop the first entry... also a bit easier to read. I would reccomend using while(1) for continous loops.

#!/usr/bin/perl -w use strict; my $LogFile="C:/test.txt"; my $naptime=3; my $logpos; #Reads LOGFILE continuously open(LOGFILE,"<$LogFile") || die "Couldn't open file Status - $!\n"; while (1) { sleep $naptime; $logpos = tell(LOGFILE); while(<LOGFILE>) { print; } seek(LOGFILE, $logpos, 0); # seek to last known }

<edit>the more I thought about it you don't even need the $logpos variable. Just use seek(LOGFILE,0,0) to seek to the beginning,since it seemed like what you wanted to do. Although if you have a specific point in the file you want to start reading from then you will need to predefine it and even then you still wouldn't need the call to tell(LOGFILE) I believe</edit>

Hope this helps.

Grygonos

In reply to Re: Re: Losing first entry of Apache log by Grygonos
in thread 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.