util_decode

one of the documented procedures in this installation of the ACS
Usage:
util_decode   args
What it does:
like decode in sql Takes the place of an if (or switch) statement -- convenient because it's compact and you don't have to break out of an ns_write if you're in one. args: same order as in sql: first the unknown value, then any number of pairs denoting "if the unknown value is equal to first element of pair, then return second element", then if the unknown value is not equal to any of the first elements, return the last arg
Defined in: /web/philip/packages/acs-core/utilities-procs.tcl

Source code:


    set args_length [llength $args]
    set unknown_value [lindex $args 0]
    
    # we want to skip the first & last values of args
    set counter 1
    while { $counter < [expr $args_length -2] } {
	if { [string compare $unknown_value [lindex $args $counter]] == 0 } {
	    return [lindex $args [expr $counter + 1]]
	}
	set counter [expr $counter + 2]
    }
    return [lindex $args [expr $args_length -1]]


philg@mit.edu