TABLE OF CONTENTS


::pwtk::ifempty

SYNOPSIS

proc ::pwtk::ifempty {varName script args} {

USAGE

   ifempty varName script ?else script2?

PURPOSE

Execute the $script only if the variable $varName is empty or does not exist.

SOURCE

    upvar $varName var

    set narg [llength $args]
    if { $narg > 0 } {
        if { [lindex $args 0] != "else" } {
            ::error "invalid command name [lindex $args 0]"
        } elseif { [llength $args] != 2 } {            
            ::error "wrong # args: should be \"if exists varName script ?else script?\""
        }
    }
    set result {}
    set code 0
    if { ! [info exists var] || $var == {} } {
        set code [catch {uplevel 1 $script} result]
    } elseif { $narg == 2} {
        set code [catch {uplevel 1 [lindex $args end]} result]
    }
    return -code $code $result
}