TABLE OF CONTENTS
::pwtk::ifexist
SYNOPSIS
proc ::pwtk::ifexist {varName script args} {
USAGE
ifexist varName script ?else script2?
PURPOSE
Execute the $script only if the variable $varName exists.
EXAMPLE
ifexist varName { puts "variable varName exists" } else { puts "variable varName 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] } { set code [catch {uplevel 1 $script} result] } elseif { $narg == 2 } { set code [catch {uplevel 1 [lindex $args end]} result] } return -code $code $result }