in reply to tracking unique users in a weblog
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (z) Re: tracking unique users in a weblog
by Earindil (Beadle) on Jan 22, 2004 at 18:47 UTC | |
|
Re: (z) Re: tracking unique users in a weblog
by Earindil (Beadle) on Jan 22, 2004 at 18:21 UTC |