|
|
||||
|
||||
|
|
|
|||
|
On 7/30/12 4:43 AM, Shimsha wrote:
> set a b > set b 7 > > Now I have to print the value of a as 7. But should not use b or any other new variable anywhere. How could this be achieved? First off, the way you are approaching the problem is very likely wrong -- consider using arrays instead. If you insist on going about your code this way, read and understand the following man pages: set subst upvar -- +------------------------------------------------------------------------+ | Gerald W. Lester, President, KNG Consulting LLC | | Email: Gerald.Lester@kng-consulting.net | +------------------------------------------------------------------------+ |
|
|||
|
On 7/30/12 4:43 AM, Shimsha wrote:
> set a b > set b 7 > > Now I have to print the value of a as 7. But should not use b or any other new variable anywhere. How could this be achieved? First off, the way you are approaching the problem is very likely wrong -- consider using arrays instead. If you insist on going about your code this way, read and understand the following man pages: set subst upvar -- +------------------------------------------------------------------------+ | Gerald W. Lester, President, KNG Consulting LLC | | Email: Gerald.Lester@kng-consulting.net | +------------------------------------------------------------------------+ |
|
|||
|
On Monday, July 30, 2012 4:43:48 AM UTC-5, Shimsha wrote:
> set a b > > set b 7 > > > > Now I have to print the value of a as 7. But should not use b or any other new variable anywhere. How could this be achieved? I don't consider it wrong. I use indirection such as this a lot. The simple answer is: puts [set $a] Of course as mentioned there are other methods as well |
|
|||
|
Le 30/07/2012 11:43, Shimsha a écrit :
> set a b > set b 7 > > Now I have to print the value of a as 7. But should not use b or any other new variable anywhere. How could this be achieved? If your goal is to define a as a reference or alias to b, upvar is what you're looking for: upvar #0 a b set b 7 puts $a => 7 (the #0 means that a and b must be in the same context) Else, you have to be a little more explicit about what you intent to achieve. |
|
|||
|
* Frederic Bonnet <fredericbonnet@free.fr>
| upvar #0 a b | set b 7 | puts $a | => 7 > | (the #0 means that a and b must be in the same context) I *think* that should be plain 0 here, since #0 addresses the global namespace. Makes a difference inside procs. R' |
|
|||
|
Le 30/07/2012 17:43, Ralf Fassel a écrit :
> * Frederic Bonnet <fredericbonnet@free.fr> > | upvar #0 a b > | set b 7 > | puts $a > | => 7 >> > | (the #0 means that a and b must be in the same context) > > I *think* that should be plain 0 here, since #0 addresses the global > namespace. Makes a difference inside procs. > > R' > Oops you're right, my bad. :blush: |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|