#!/usr/bin/perl 

use Fcntl ':seek';

print "Content-Type: text/html\n\n";

my $path = "data/counter.dat";

# Create if not yet exist
if (! -f $path) {
	open LOG, ">$path";
	print LOG "0";
	close LOG;
}

# If cannot be opened, return a '?' for display
if (!open(LOG, "+<$path")) {
	print "?";
	exit 0;
}

chomp($num = <LOG>);
truncate LOG, 0;
seek(LOG, 0, SEEK_SET);
defined($num) or $num = 0;
++$num;
print LOG "$num";
close LOG;
print $num;
