1#!/depot/path/tclsh
2
3# This is a CGI script that displays the environment or another array.
4
5package require cgi
6
7cgi_eval {
8    source example.tcl
9
10    proc arrays {} {
11	uplevel #0 {
12	    set buf {}
13	    foreach a [info globals] {
14		if {[array exists $a]} {
15		    lappend buf $a
16		}
17	    }
18	    return $buf
19	}
20    }
21
22    cgi_input
23
24    cgi_title "Display environment or another array"
25
26    cgi_body {
27	p "This script displays the environment or another array."
28	if {[catch {cgi_import Name}]} {
29	    set Name env
30	}
31
32	cgi_form parray {
33	    cgi_select Name {
34		foreach a [arrays] {
35		    cgi_option $a selected_if_equal=$Name
36		}
37	    }
38	    cgi_submit_button
39	}
40
41	global $Name
42	if {[array exist $Name]} {
43	    cgi_parray $Name
44	} else {
45	    puts "$Name: no such array"
46	}
47    }
48}
49