summaryrefslogtreecommitdiff
path: root/web/src/cgi.tcl-1.10/example/parray.cgi
blob: a4c23316260cb611328636213387d58088301883 (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
#!/depot/path/tclsh

# This is a CGI script that displays the environment or another array.

package require cgi

cgi_eval {
    source example.tcl

    proc arrays {} {
	uplevel #0 {
	    set buf {}
	    foreach a [info globals] {
		if {[array exists $a]} {
		    lappend buf $a
		}
	    }
	    return $buf
	}
    }

    cgi_input

    cgi_title "Display environment or another array"

    cgi_body {
	p "This script displays the environment or another array."
	if {[catch {cgi_import Name}]} {
	    set Name env
	}

	cgi_form parray {
	    cgi_select Name {
		foreach a [arrays] {
		    cgi_option $a selected_if_equal=$Name
		}
	    }
	    cgi_submit_button
	}

	global $Name
	if {[array exist $Name]} {
	    cgi_parray $Name
	} else {
	    puts "$Name: no such array"
	}
    }
}