Do we need to “undo” variables in TCL?

Is this a requirement for good TCL code? What happens if we do not use the "unset" keyword in the script? Any ulcers that I should know about?

I inherit some kind of legacy code, and errors that occur due to "undefined" non-existent variables push me to the wall!

+5
source share
4 answers

You can determine if a variable exists before using it using the command info exists. Make sure that if you are not using unset, you are not breaking the logic of the program elsewhere.

Tcl unset, .. - . unset , , . , , .

+8

, Tcl , :

unset -nocomplain foo

foo, , , .

+2

, " ", script . , , " XXXXXXXX".

Make sure that you do not store so much data in variables, otherwise disconnect them as soon as the use ends for the corresponding data sets (variables)

+1
source

Note that I cannot comment on the “information exists” above;

I often use this form.

if { [info exists pie] && [$pie == "ThisIsWhatIWantInPie"]} {
    puts "I found what I wanted in pie."
} else {
    puts "Pie did not exist; but I still did not error,TCL evaluation \
          will see the conditional failed on the [info exists] and not \
          continue onto the comparison."
}
0
source

All Articles