TABLE OF CONTENTS


::pwtk::ifnotempty

SYNOPSIS

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

USAGE

   ifnotempty varName script ?else script2?

PURPOSE

Execute the $script only if the variable $varName exists and is not empty.

SOURCE

    upvar $varName var

    set narg [llength $args]
    if { $narg > 0 } {
        if { [lindex $args 0] != "else" } {
            ::error "invalid command name [lindex $args 0]"
        } elseif { $narg != 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
}