Jun 13, 2000, 9:00 PM
Post #2 of 3
You probably want to use File::CounterFile instead as it has error checking and uses flock() to enforce serial updates.
The 0 padding issue is also a doddle with (s)printf.
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>
my $url = 'http://www.com/web/scripts/count/digits';
my $ext = 'gif';
my $file = '/home/www/web/scripts/count/count.txt';
printf q(<img src="%s/%08d.%s"> ),
File::CounterFile->new( $file, 0 )->inc,
As for the 'reload protection', I'm not an advocate of using IPs as unique identifiers: it's becoming more and more common for people to be using a proxy of some sort, and while you only see 1 IP, there may be 10s, 100s, or 1000s of people sharing that same IP.
If you must use IPs, then the easiest, efficient way I can think of would be to write the IPs out to a directory as filenames and then use the -M file test operator to help identify which filenames/IPs to delete after a day.
That way, you could check if the IP exists as a file: if it does, do nothing; if it doesn't, increment the counter.