Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

upvar problem 1

Status
Not open for further replies.

marsd

IS-IT--Management
Apr 25, 2001
2,218
US
I am not catching some of the nuances of passing variables
between stacklevels here..if someone could explain what I
am doing wrong I would appreciate it;-)

If I have code that looks like this:
#script main

set R 12

proc echo_val {N} {
upvar #0 $N loc
puts "Local value of proc arg $N is $loc"
}

echo_val $R
#end

"Error is can't read loc, no such variable."

Which seems pretty bizarre to me since from what
I understand upvar aliases point to a value up the stack.
I have also read that the statement upvar #0 is
equivalent to the global declaration.
I have used upvar with the tcl_http package with no
problem so this simple translation of variable aliases
is baffling me.
Does the upvar alias have to exist in the same scope
as the original var?
 
You only need to replace
echo_val $R
by
echo_val R

You must pass to echo_val the name of the global variable, not its value.

ulis
 
Geez, what a lamebrain trick.

You saved me a rewrite.

Thanks Ulis.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top