
Borderline
Deleted
Jan 20, 2000, 9:27 PM
Post #2 of 10
(9959 views)
|
Hi, perlfaq5 has writen this script for you <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> I still don't get locking. I just want to increment the number in the file. How can I do this? Didn't anyone ever tell you web-page hit counters were useless? They don't count number of hits, they're a waste of time, and they serve only to stroke the writer's vanity. Better to pick a random number. It's more realistic. Anyway, this is what you can do if you can't help yourself. use Fcntl ':flock'; sysopen(FH, "numfile", O_RDWR|O_CREAT) or die "can't open numfile: $!"; flock(FH, LOCK_EX) or die "can't flock numfile: $!"; $num = <FH> | | 0; seek(FH, 0, 0) or die "can't rewind numfile: $!"; truncate(FH, 0) or die "can't truncate numfile: $!"; (print FH $num+1, "\n") or die "can't write numfile: $!"; # Perl as of 5.004 automatically flushes before unlocking flock(FH, LOCK_UN) or die "can't flock numfile: $!"; close FH or die "can't close numfile: $!"; Here's a much better web-page hit counter: $hits = int( (time() - 850_000_000) / rand(1_000) ); If the count doesn't impress your friends, then the code might. :-) </pre><HR></BLOCKQUOTE> If you really need to keep track of the people coming to your site use the Log Files. Scott [This message has been edited by Borderline (edited 01-20-2000).]
|