#!/usr/bin/perl -w # Name : Perl Cached Clock # Author : Terrence Ma # Email : terrence@terrence.com # Web : http://www.terrence.com # Date : V1.1 10/03/2001, V1.0 01/28/2001 # License : GNU GPL - http://www.gnu.org/copyleft/gpl.html # Warranty : No Warranty # use lib use 5; use strict; use Fcntl qw(:DEFAULT :flock); use CGI::Pretty; # init variables my $cgi = new CGI; my $title = "Perl Cached Clock"; my $comment = "Cached Every 10 Minutes :"; my $cache = "/virtual/customer/terrence.com/htdocs/perl/cache/cache.html"; my $source = "http://www.terrence.com/perl/cache/cache.txt"; my $timezone = ((localtime)[8] == 0) ? " CST" : " CDT"; my $timenow = scalar(localtime()) . $timezone; # open file open(CACHE, "> $cache") || die "Can't write to $cache: $!"; flock(CACHE, LOCK_EX) || die "Can't lock filename: $!"; # main program # print page # print header # no $cgi->header() print CACHE $cgi->start_html($title); print CACHE $cgi->center($cgi->h1($title)), $cgi->hr(), $cgi->br(); # print body print CACHE $cgi->center($cgi->b($comment)), $cgi->br(); print CACHE $cgi->center ( $cgi->table ( {-border=>"1"}, $cgi->Tr ( $cgi->td ( {-align=>"center", -bgcolor=>"#0000ff"}, $cgi->font({-color=>"#ffffff"}, $cgi->b("$title")) ) ), $cgi->Tr ( $cgi->td ( {-align=>"center"}, $timenow ) ) ) ); # print footer print CACHE $cgi->br(), $cgi->hr(), $cgi->a({-href=>$source}, "Program Source"), $cgi->br(), $cgi->end_html(); # close file close(CACHE); exit(0);