TABLE OF CONTENTS


::pwtk::ifset

SYNOPSIS

proc ::pwtk::ifset {name value} {

USAGE

   ::pwtk::ifset varName value
   ::pwtk::ifset arrayName {element value ?element value? ...}

DESCRIPTION

If 'name' is a variable:

If 'name' is an array:

BEWARE

::pwtk::ifset will assign array elements only if the array 'name' already exists.

ARGUMENTS

RETURN VALUE

SOURCE

    upvar $name var

    if { [array exists var] } {
        if { [llength $value] % 2 } {
            ::error "element-value list must have an even number of elements"
        }
        foreach {e v} $value {
            if { ! [info exists var($e)] || $var($e) eq {} } {
                set var($e) $v
            }
        }
        return {}        
    } else {
        if { [info exists var] && $var ne {} } {
            return $var
        } else {
            return [set var $value]
        }
    }
}