Thursday, July 12, 2012

Easiest Example for upvar in TCL


Usage:

Used when we have to change the value of a global variable from inside a procedure’s scope

Example
proc example {one two} {
upvar $one local1
upvar $two local2

set local1 Kavitha
set local2 Anbarasu

}

set glob1 David
set glob2 Beckam

puts $glob1
puts $glob2\n

example glob1 glob2
puts $glob1
puts $glob2

Output
David
Beckam

Kavitha
Anbarasu

In the above example we are able to change the value of two global variables glob1 and glob2 from within a procedure

14 comments:

  1. Nice.. I understood clearly now. Thanks

    ReplyDelete
  2. Good and simple example Kavitha. Thank you for making me understanding this concept.

    ReplyDelete
  3. I'm scratching my head actually.Thanks :)

    ReplyDelete
  4. Thanks a lot Kavitha.....very nice and simple explanation of upvar... :)
    cheers

    ReplyDelete
  5. Holy sizz if this didnt make this so damn simple to understand. All this extra fluff and convolution in the other sources. You rock!

    ReplyDelete