|
From: Anonymous R. (austria) <mix...@re...> - 2012-03-29 12:20:45
|
Hi I posted this to comp.lang.tcl but haven't gotten any replies. Maybe this list would be a better place to ask? My question is is it better to initialize all variables in a script whether they might be used or not or better to test with info exists? I am scanning some text and variables only get created if specific patterns match. I found out if I test a variable that didn't get created for the empty string the script gets an error. Ok. I "solved" this by doing set for all the possibly used variables to the empty string "". Looking a bit further I see I could use info exists. Tcl noob as I am, I don't know whether info exists is preferable or initializing lots of variables that may not be used is better. I don't mind the memory consumption of creating variables that might not be used. The question is whether there's any benefit in Tcl to defining variables that might not be used and if that is the right way to do this in Tcl or should I use info exists? I would prefer to do it idiomatically, with a priority on clarity and then performance and then storage consumption in that order. Of course I want to do it like a Tcler. In the last few days since I posted I switched to using info exists I hope that is the better way. Thanks guys. |