#!/usr/bin/perl # はてな足あと帳 by Hamachiya2. # 2005/12/07 use CGI; use CGI::Carp qw(fatalsToBrowser); my $q = new CGI; print $q->header(-charset=>'UTF-8'); my $id = $q->param('i'); #if ($id =~ /^[a-zA-Z0-9]+$/) { $id = "hatena:$id"; #} else { # $id ="へんなクエリ送ってきたひと? ($id)"; #} $id = $q->escapeHTML($id); my $lockfile = "lockfile.loc"; my $datafile = "count.txt"; my $tempfile = "count.tmp"; my ($ss, $mn, $hh, $dd, $mm, $yy) = localtime(time); $yy += 1900; $mm++; my $dttm = sprintf("[%04d/%02d/%02d %02d:%02d:%02d]", $yy, $mm, $dd, $hh, $mn, $ss); $dttm = "$dttm $id\n"; my @log; open(LOCK, $lockfile); flock(LOCK, 2); while (1) { open(IN, $datafile) or last; @log = ; close(IN); unshift(@log, $dttm); open(OUT, "> $tempfile") or last; foreach(@log) { print OUT $_ or last; } close(OUT) or last; rename($tempfile, $datafile); last; } close(LOCK); print eatHere(<<"_EoD_", '#'); ## ## ## ## はてな足あと帳 :: ぼくはまちちゃん! ## ## ##
_EoD_ foreach(@log) { print "$_
"; } print eatHere(<<"_EoD_", '#'); ##
## ## _EoD_ sub eatHere { my $target = shift; my $sym = shift; my $indent = shift; $target =~ s/^[^\S\n]+//gm; $target =~ s/^$sym+//gm; $indent or do { $target =~ s/^[^\S\n]+//gm; }; return $target; }