3
# This script implements the "Virtual Clock" used as the example in the
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.
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.) See other comments after script. - Don
20
if {[llength [cgi_import_list]]} {
21
if 0==[catch {cgi_import time}] {
22
append format [expr {[cgi_import type] == "12-hour"?"%r ":"%T "}]
24
catch {cgi_import day; append format "%A "}
25
catch {cgi_import month; append format "%B "}
26
catch {cgi_import day-of-month; append format "%d "}
27
catch {cgi_import year; append format "%Y "}
29
append format "%r %A %B %d %Y"
32
set time [clock format [clock seconds] -format $format]
34
cgi_title "Virtual Clock"
37
puts "At the tone, the time will be [strong $time]"
43
foreach x {time day month day-of-month year} {
44
cgi_checkbox $x checked
49
cgi_radio_button type=12-hour checked;put "12-hour"
50
cgi_radio_button type=24-hour ;put "24-hour"
53
cgi_submit_button =Set
60
# Time/date generation is built-in to Tcl. Thus, no extra processes
61
# are necessary and the result is portable. In contrast, CGI.pm
64
# Displaying checkboxes side by side the way that CGI.pm does by
65
# default is awful. The problem is that with enough buttons, it's not
66
# immediately clear if the button goes with the label on the right or
67
# left. So cgi.tcl does not supply a proc to generate such a
68
# grouping. I've followed CGI.pm's style here only to show that it's
69
# trivial to get the same affect, but the formatting in any real form
70
# is more wisely left to the user.
72
# Footer generation (<hr><address>... at end of CGI.pm) is replaced
73
# by "source example.tcl". Both take one line.