mod_dtcl examples

These are some examples, rather limited ones, of what can be done with mod_dtcl.

\n" for {set j 1} {$j <= 8} {incr j} { set num [ expr {$i * $j * 4 - 1} ] hputs [ format "\n" $num $num $num ] } incr i hputs "\n" } hputs "

Hello world

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

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

hputs "Hello world"
?>

Produces:


Conditionals:

<? if { 1 } { ?>

<h2> True </h2>

<? }  ?>

Produces:

True


Loops:

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

LOOP<br>

<? }  ?>

Produces:

" incr x ?> LOOP


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


<? 
 hgetvars
if { [ array exists VARS ] } {
    hputs "< ul>"
    foreach { vr } [ array names VARS ]  {
        hputs "<li>(VARS) $vr = $VARS($vr)"
    }
    hputs "</ul>"
}

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

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

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

?>

Produces:

" foreach { vr } [ array names VARS ] { hputs "

  • (VARS) $vr = $VARS($vr)" } hputs "" } if { [ array exists ENVS ] } { hputs "
      " foreach { vr } [ array names ENVS ] { hputs "
    • (ENVS) $vr = $ENVS($vr)" } hputs "
    " } if { [ array exists CLIENT_ENVS ] } { hputs "
      " foreach { vr } [ array names CLIENT_ENVS ] { hputs "
    • (CLIENT_ENVS) $vr = $CLIENT_ENVS($vr)" } hputs "
    " } if { [ array exists COOKIES ] } { hputs "
      " foreach { vr } [ array names COOKIES ] { hputs "
    • (COOKIES) $vr = $COOKIES($vr)" } hputs "
    " } ?>

  • Create a table on the fly

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

    \n" while { $i <= 8 } { hputs "

    $num $num $num
    \n" ?>


    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!

    Return to the mod_dtcl homepage