Overview
| Artifact ID: | 1abb942776d1353c52f1c2dfea1d33d9b1d137db |
|---|---|
| Ticket: | 1587442fffffffffffffffffffffffffffffffff
let upvar only create variables in the current context |
| User & Date: | msofer on 2006-11-03 22:18:19 |
Changes
- icomment:
Logged In: YES user_id=148712 The idea is that you [namespace eval] in the namespace where you want your variables to be created; I would code your algorithm as set tcnt -1 foreach ns {ns1 ns2 ns3} { set lst [list namespace upvar [namespace current]] for {set cnt 0} {$cnt < 5} {incr cnt} { foreach arn {arr lis dic} { lappend lst $arn[incr tcnt] $arn$cnt } } namespace eval $ns $lst } On the other hand, your current algorithm I would also code somewhat differently. Note that upvar #0 [namespace current]::x ::a::y is equivalent to the faster (and IMO clearer) upvar 0 x ::a::y So, I would now code yours as set tcnt -1 set lst [list upvar 0] foreach ns {ns1 ns2 ns3} { for {set cnt 0} {$cnt < 5} {incr cnt} { foreach arn {arr lis dic} { lappend lst $arn[incr tcnt] ::${ns}::$arn$cnt } } } eval $lst - login: "msofer"
- mimetype: "text/plain"
- username: "msofer"