#!/development/perl/bin/perl #=============================================== use strict; use vars qw/$PATH/; use Fcntl qw/:flock/; $PATH = q[/development/apache2/cgi-bin/hits.txt]; main(); #=============================================== sub main { #----------------------------------------------- # Read and write the counts. my $out = _read_hits(); my $in = _write_hits(++$out); # Do something here like print the hits using $in print "Content-type: text/html\n\n"; print $in; } sub _read_hits { #----------------------------------------------- # Load the total hits. my $fh = \do { local *FH; *FH }; open $fh, $PATH or die qq[$0: $PATH: $!]; flock $fh, LOCK_SH; read ($fh, my $hits, -s $fh); $hits++; } sub _write_hits { #----------------------------------------------- # Write the total hits. my $fh = \do { local *FH; *FH }; open $fh, '>', $PATH or die qq[$0: $PATH: $!]; flock $fh, LOCK_EX; print $fh $_[0]; $_[0]; }