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:
- set a variable $name only if does not exist or has an empty value.
If 'name' is an array:
- set a given array element only if does not exist or has an empty value.
BEWARE
::pwtk::ifset will assign array elements only if the array 'name' already exists.
ARGUMENTS
- name -- name of the variable or array (aka varName or arrayName)
- value -- either a value to set the variable to or "element value" pairs for an array
RETURN VALUE
- if 'name' is a variable, the value of the variable.
- if 'name' is an array, an empty string.
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] } } }