summaryrefslogtreecommitdiff
path: root/web/src/cgi.tcl-1.10/example/vclock.pl
blob: 0605f0c79e819f4b2cd1e48fa69f12f6f8f0fcf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/local/bin/perl

# This script is the "Virtual Clock" example in the seminal
# paper describing CGI.pm, a perl module for generating CGI.
# Stein, L., "CGI.pm: A Perl Module for Creating Dynamic HTML Documents
# with CGI Scripts", SANS 96, May '96.

# Do you think it is more readable than the other version?
# (If you remove the comments and blank lines, it's exactly
# the same number of lines.) - Don

use CGI;
$q = new CGI;

if ($q->param) {
    if ($q->param('time')) {
	$format = ($q->param('type') eq '12-hour') ? '%r ' : '%T';
    }

    $format .= '%A ' if $q->param('day');
    $format .= '%B ' if $q->param('month');
    $format .= '%d ' if $q->param('day-of-month');
    $format .= '%Y ' if $q->param('year');
} else {
    $format = '%r %A %B %d %Y';
}

$time = `date '+$format'`;

# print the HTTP header and the HTML document
print $q->header;
print $q->start_html('Virtual Clock');
print <<END;
<H1>Virtual Clock</H1>
At the tone, the time will be <STRONG>$time</STRONG>.
END

print <<END;
<HR>
<H2>Set Clock Format</H2>
END

# Create the clock settings form
print $q->start_form;
print "Show: ";
print $q->checkbox(-name->'time',-checked=>1);
print $q->checkbox(-name->'day',-checked=>1);
print $q->checkbox(-name->'month',-checked=>1);
print $q->checkbox(-name->'day-of-month',-checked=>1);
print $q->checkbox(-name->'year',-checked=>1);
print "<P>Time style:";
print $q->radio_group(-name=>'type',
		      -values=>['12-hour','24-hour']),"<P>";
print $q->reset(-name=>'Reset'),
      $q->submit(-name=>'Set');
print $q->end_form;

print '<HR><ADDRESS>webmaster@ferrets.com</ADDRESS>'
print $q->end_html;