mod_dtcl examples

These are some examples, rather limited ones, of what can be done with mod_dtcl. Note: because mod_dtcl is no longer part of the main Apache Tcl site (see Rivet instead), this page is no longer a live mod_dtcl script.


Hello world

<?
headers setcookie "foo" "bar" # we have to put this before any 'puts' statements

# once buffering is switched off, it is no longer possible to
# maninuplate headers
buffered off

puts "Hello world"
?>

Produces:

hello world


Conditionals:

<? if { 1 } { ?>

<h2> True </h2>

<? }  ?>

Produces:

True


Loops:

<? 
set x 0 
while { $x < 5 } { 
 puts "\$x = $x<br>"
 incr x
?>

LOOP<br>

<? }  ?>

Produces:

$x = 0
LOOP
$x = 1
LOOP
$x = 2
LOOP
$x = 3
LOOP
$x = 4
LOOP


Variables (environmental as well as those passed to the script)


<? 
 hgetvars
if { [ array exists VARS ] } {
    puts "< ul>"
    foreach { var val } [ var all ]  {
        puts "<li>(VARS) $var = $val"
    }
    puts "</ul>"
}

if { [ array exists ENVS ] } {
    
    puts "<ul>"
    foreach { vr } [ array names ENVS ]  {
        puts "<li>(ENVS) $vr = $ENVS($vr)"
    }
    puts "</ul>"
}

if { [ array exists COOKIES ] } {
    
    puts "<ul>"
    foreach { vr } [ array names COOKIES ]  {
        puts "<li>(COOKIES) $vr = $COOKIES($vr)"
    }
    puts "</ul>"
}

?>

Produces:

  • (ENVS) DATE_LOCAL = Saturday, 24-May-2003 18:05:46 CEST
  • (ENVS) SERVER_ADDR = 127.0.0.1
  • (ENVS) DOCUMENT_ROOT = /var/www/tcl-site/
  • (ENVS) GATEWAY_INTERFACE = CGI/1.1
  • (ENVS) SERVER_PORT = 80
  • (ENVS) HTTP_HOST = tclsite
  • (ENVS) DATE_GMT = Saturday, 24-May-2003 16:05:46 GMT
  • (ENVS) REMOTE_ADDR = 127.0.0.1
  • (ENVS) DOCUMENT_URI = /mod_dtcl/examples.ttml
  • (ENVS) SERVER_NAME = tclsite
  • (ENVS) HTTP_CONNECTION = keep-alive
  • (ENVS) SERVER_SIGNATURE =
  • (ENVS) SERVER_PROTOCOL = HTTP/1.1
  • (ENVS) REQUEST_URI = /mod_dtcl/examples.ttml
  • (ENVS) REMOTE_PORT = 59939
  • (ENVS) HTTP_ACCEPT_CHARSET = ISO-8859-1, utf-8;q=0.66, *;q=0.66
  • (ENVS) SERVER_SOFTWARE = Apache/1.3.26 (Unix) Debian GNU/Linux Rivet mod_dtcl
  • (ENVS) REQUEST_METHOD = GET
  • (ENVS) HTTP_ACCEPT_LANGUAGE = en, it;q=0.50
  • (ENVS) UNIQUE_ID = Ps@YWn8AAAEAACiR-24
  • (ENVS) QUERY_STRING =
  • (ENVS) HTTP_USER_AGENT = Mozilla/5.0 Galeon/1.2.5 (X11; Linux ppc; U;) Gecko/20020622 Debian/1.2.5-0.woody.1
  • (ENVS) HTTP_KEEP_ALIVE = 300
  • (ENVS) LAST_MODIFIED = Friday, 25-Oct-2002 07:21:04 CEST
  • (ENVS) SCRIPT_NAME = /mod_dtcl/examples.ttml
  • (ENVS) SCRIPT_FILENAME = /var/www/tcl-site/mod_dtcl/examples.ttml
  • (ENVS) PATH = /bin:/usr/bin:/sbin:/usr/sbin
  • (ENVS) HTTP_ACCEPT_ENCODING = gzip, deflate, compress;q=0.9
  • (ENVS) DOCUMENT_PATH_INFO =
  • (ENVS) SERVER_ADMIN = webmaster@ashland
  • (ENVS) USER_NAME = davidw
  • (ENVS) DOCUMENT_NAME = examples.ttml
  • (ENVS) HTTP_ACCEPT = text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1

Create a table on the fly


<?
set i 1
puts "<table>\n"

while { $i <= 8 } {
    puts "<tr>\n"
    for {set j 1} {$j <= 8} {incr j} {
	set num [ expr $i * $j * 4 - 1]
	puts [ format "<td bgcolor=%2x%2x%2x > $num $num $num </td>\n" $num $num $num ]
    }
    incr i
    puts "</tr>\n"
}

puts "</table>\n"
?>
Produces:

3 3 3 7 7 7 11 11 11 15 15 15 19 19 19 23 23 23 27 27 27 31 31 31
7 7 7 15 15 15 23 23 23 31 31 31 39 39 39 47 47 47 55 55 55 63 63 63
11 11 11 23 23 23 35 35 35 47 47 47 59 59 59 71 71 71 83 83 83 95 95 95
15 15 15 31 31 31 47 47 47 63 63 63 79 79 79 95 95 95 111 111 111 127 127 127
19 19 19 39 39 39 59 59 59 79 79 79 99 99 99 119 119 119 139 139 139 159 159 159
23 23 23 47 47 47 71 71 71 95 95 95 119 119 119 143 143 143 167 167 167 191 191 191
27 27 27 55 55 55 83 83 83 111 111 111 139 139 139 167 167 167 195 195 195 223 223 223
31 31 31 63 63 63 95 95 95 127 127 127 159 159 159 191 191 191 223 223 223 255 255 255


In addition
There are many, many other things you can do with mod_dtcl. You can, if everything is compiled right, load tcl modules, like libpgtcl.so (the Postgresql interface), so that you can interact with a database!

dtcl_info
Free cache size: 9
PID: 10385

Return to the mod_dtcl homepage