#!/usr/bin/env perl
print "Content-Type: text/html\n\n";
$cfile="ecounter.dat";
$hfile="esample.html";
$match_str = "ACCESS_COUNTER";
# カウンタの値を読み込む
if (open(FH, $cfile)) {
$counter = + 1;
close(FH);
} else {
$counter = 1;
}
# カウンタの値を書き込む
open(FH, ">" . $cfile) or die "Cannot write counter file!";
print FH $counter;
close(FH);
# HTMLファイルを読み込み、その内容を出力する
open(FH, $hfile);
while () { # ファイルから1行読み込む
if ($_ =~ /$match_str/) {
$_ = $counter . "\n";
}
print $_; # 1行分を標準出力に出力
}
close(FH);