1#!/usr/local/bin/perl 2 3# This script is the "Virtual Clock" example in the seminal 4# paper describing CGI.pm, a perl module for generating CGI. 5# Stein, L., "CGI.pm: A Perl Module for Creating Dynamic HTML Documents 6# with CGI Scripts", SANS 96, May '96. 7 8# Do you think it is more readable than the other version? 9# (If you remove the comments and blank lines, it's exactly 10# the same number of lines.) - Don 11 12use CGI; 13$q = new CGI; 14 15if ($q->param) { 16 if ($q->param('time')) { 17 $format = ($q->param('type') eq '12-hour') ? '%r ' : '%T'; 18 } 19 20 $format .= '%A ' if $q->param('day'); 21 $format .= '%B ' if $q->param('month'); 22 $format .= '%d ' if $q->param('day-of-month'); 23 $format .= '%Y ' if $q->param('year'); 24} else { 25 $format = '%r %A %B %d %Y'; 26} 27 28$time = `date '+$format'`; 29 30# print the HTTP header and the HTML document 31print $q->header; 32print $q->start_html('Virtual Clock'); 33print <<END; 34<H1>Virtual Clock</H1> 35At the tone, the time will be <STRONG>$time</STRONG>. 36END 37 38print <<END; 39<HR> 40<H2>Set Clock Format</H2> 41END 42 43# Create the clock settings form 44print $q->start_form; 45print "Show: "; 46print $q->checkbox(-name->'time',-checked=>1); 47print $q->checkbox(-name->'day',-checked=>1); 48print $q->checkbox(-name->'month',-checked=>1); 49print $q->checkbox(-name->'day-of-month',-checked=>1); 50print $q->checkbox(-name->'year',-checked=>1); 51print "<P>Time style:"; 52print $q->radio_group(-name=>'type', 53 -values=>['12-hour','24-hour']),"<P>"; 54print $q->reset(-name=>'Reset'), 55 $q->submit(-name=>'Set'); 56print $q->end_form; 57 58print '<HR><ADDRESS>webmaster@ferrets.com</ADDRESS>' 59print $q->end_html; 60