Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

do we need to "unset" variables in TCL?

Tags:

unset

tcl

Is it a requirement of good TCL code? What would happen if we don't use the "unset" keyword in a script? Any ill-effects I should know about?

I'm inheriting some legacy code and the errors that come about due to "unset"-ing non-existent variables are driving me up the wall!

like image 689
chronodekar Avatar asked Feb 25 '10 05:02

chronodekar


2 Answers

It's possible to determine whether a variable exists before using it, using the info exists command. Be sure that if you're not using unset, that you don't upset the logic of the program somewhere else.

There's no Tcl-specific reason to unset a variable, that is, it's not going to cause a memory leak or run out of variable handles or anything crazy like that. Using unset may be a defensive programming practice, because it prevents future use of a variable after it's no longer relevant. Without knowing more about the exact code you're working with, it's hard to give more detailed info.

like image 198
Greg Hewgill Avatar answered Sep 23 '22 09:09

Greg Hewgill


In addition to the other responses, if your Tcl version is new enough, you can also use:

unset -nocomplain foo

That'll unset foo if it exists, but won't complain if it doesn't.

like image 45
Jeff Godfrey Avatar answered Sep 24 '22 09:09

Jeff Godfrey