#!/usr/bin/perl
#!C:/Perl/bin/perl
# 初期化
# ヘッダ部の出力
print "Content-type: text/html\n\n";
&printdata( 'rephead.txt' );
# アクセス数の表を作る
$dayfrom = 30;
$jstime = time + 9*60*60; # 現在時刻
@youbi = qw( 日 月 火 水 木 金 土 );
$countmax = 0;
for( $iday = $dayfrom; $iday >= 0; $iday-- )
{
# ログファイル名の作成
( $sec, $min, $hour, $day, $mon, $year, $weekday ) = gmtime( $jstime - $iday*24*60*60 );
$mon += 1;
$date = sprintf( "%02d-%02d-%02d", $year-100, $mon, $day );
$logfile = '../log/' . $date . '.txt';
# アクセス数のカウント
$access[ $iday ] = $access = &countaccess( $logfile );
if( $countmax < $access ) {
$countmax = $access;
}
}
# ヘッダー出力
print '
', "\n";
for( $iday = $dayfrom; $iday >= 0; $iday-- )
{
print " \n";
$num = $access[ $iday ];
$graph = $num/$countmax*200;
# 日付の作成
( $sec, $min, $hour, $day, $mon, $year, $weekday ) = gmtime( $jstime - $iday*24*60*60 );
$mon += 1;
$date = " $mon/$day(" . $youbi[$weekday] . ") ";
# 日付の出力
print " ";
if( $weekday == 0 ) {
print "" . $date . "";
} elsif( $weekday == 6 ) {
print "" . $date . "";
} else {
print $date;
}
print " | \n";
# アクセス数の出力
print " ";
printf " %d ", $num;
print " | \n";
# グラフの出力
&PrintGraph( $graph, $num );
print "
\n";
}
print "
\n";
# フッタ部の出力
FOOTER:
&printdata( 'reptail.txt' );
exit;
########
# エントリの読み込みとカウント
sub countaccess
{
my( $logfile ) = @_;
my( $count );
# ファイルのオープン
if( ! open( LOG, $logfile ) ) {
return 0;
}
# エントリの読み込み
$count = 0;
while( )
{
chomp;
if( $_ eq "" ) {
$count++;
}
}
# ファイルのクローズ
close LOG;
return $count;
}
########
# DATAの出力
sub printdata
{
if( open( TEXT, $_[ 0 ] ) )
{
while( )
{
print $_;
}
close TEXT;
}
}
########
# グラフを書く
sub PrintGraph
{
my( $value, $per ) = @_;
my( $num );
$num = int( $value + 0.5 );
$per = int( $per + 0.5 );
print " ";
if( $num > 0 ) {
printf "", $num, $num, $per;
}
print " | \n";
}