Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I create a namespace where the name is contained in one variable:

set fg_path fg_$path
namespace eval $fg_path {
    variable Elem 17
    puts "--> [namespace current]"
}

But I am not able to access the Elem value or to set it, for example this doesn't works: set ::$fg_path::Elem [dict create]

Thanks for any suggestion. John


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.9k views
Welcome To Ask or Share your Answers For Others

1 Answer

You have to be careful when assembling the qualified variable name:

set ::${fg_path}::Elem [dict create]

Note the curly braces { and } which protect the variable fg_path for variable substitution. Without them, you would ask Tcl to run substitution for a variable named fg_path::Elem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...