#!/opt/bin/perl -Tw #++ # Based on time4.pl (pp. 47 - 49) from # _Official Guide to Programming with CGI.pm: The Standard for Building # Web Scripts_ # by Lincoln Stein # (c) 1998 byLincoln Stein # Published by John Wiley & Sons, Inc. # # Source code time4.pl at # #-- use CGI qw(-debug :standard); use POSIX 'strftime'; # constants use constant LOCAL => 'Atlantic'; use constant GMT => 'Standard'; # get initial values my $zone = param('zone'); my $style = param('style'); $style = "12" if not defined $style; $zone = LOCAL if not defined $zone; # print the HTTP header and the HTML document start_xhtml(); $current_time = now($zone, $style); print "

The current time is ", $current_time, " ", $zone, ".

\n"; print_form($zone, $style, $current_time); finish_xhtml(); #-- subs begin --# sub start_xhtml { print header; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print " A Virtual Clock\n"; print "\n"; print "\n"; print "

A Virtual Clock

\n"; } # start_xhtml() sub finish_xhtml { print "
\n"; print "

valid?

\n"; print "

list of examples

\n"; print "\n"; print "\n"; } # finish_xhtml() # get the time in the specified format sub now { my ($zone, $style) = @_; my $format; $format = ($style eq '12') ?'%r' :'%T'; if ($zone eq LOCAL) { return strftime($format,localtime); } else { return strftime($format,gmtime); } } # now() # print the clock settings form sub print_form { my ($zone, $style) = @_; print ' ', "\n"; print ' ', "\n"; print ' ', "\n"; print ' ', "\n"; print ' ', "\n"; print ' ', "\n"; print ' ', "\n"; print ' ', "\n"; print ' ', "\n"; print ' ', "\n"; print ' ', "\n"; print '
ZoneFormat
', "\n"; print ' ', "\n"; print ' Atlantic', "\n"; print ' ', "\n"; print ' ', "\n"; print ' 12-hour', "\n"; print '
', "\n"; print ' ', "\n"; print ' Greenwich', "\n"; print ' ', "\n"; print ' ', "\n"; print ' 24-hour ', "\n"; print '
', "\n"; print '

', "\n"; print ' ', "\n"; } # print_form() ## End of Example ##