First, I'd try to write this a a daemon, as merlyn hints. If that isn't possible, then using seek will defenitly be a lot faster than reading each line in the long, spliiting, it, and comparing it with the timestamp you need. Something like this (untested) code:

# get last known position of EOF if (open(SEEK, "<seek") { $seek = <SEEK>; chomp $seek; close SEEK; } else { # no EOF recorded, find it warn "Failed to read seek: $!\nCreating\n"; open(LOG, "<$log") or die "Can't read $log: $!"; # always a good idea to check the result of your open! seek(LOG, 0, 2); # jump to the EOF $seek = tell(LOG); close LOG; &write_seek($seek); exit; } open(LOG, "<$log") or die "Can't read $log: $!"; seek(LOG, $seek, 0); # jump to the last EOF while (<LOG>) { $id = (split / /)[2]; $login_id{$id}++; } $seek = tell(LOG); &write_seek($seek); close LOG; sub write_seek { my $seek = shift; open(SEEK, ">seek") or die "Can't write to seek: $!"; print SEEK $seek; close SEEK; }

Remember, this code has not been even compiled.

-- zigdon


In reply to (z) Re: tracking unique users in a weblog by zigdon
in thread tracking unique users in a weblog by Earindil

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.