|
From: miguel s. <mi...@ut...> - 2004-03-30 21:38:28
|
Larry Smith wrote:
>
>> One example is:
>> upvar 0 x(1) y(1)
>>
>> which creates a /scalar/ variable named y(1) that is linked to the
>> element 1 of the array x. However, there is no way for a tcl script
>> to read or write such scalar variables, the parser will interpret
>> that name as referring to an element of the array named y.
>
>
> % global x(1)
> % set {x(1)} foo
> foo
> % puts ${x(1)}
> foo
>
>
>
% proc a {} {
global x(1)
set {x(1)} foo
foreach n [info vars] {
catch {append res "$n: [set $n]"}
}
puts $res
info vars
}
% a
x(1): foo
n res x x(1)
% info vars x*
x
% set x(1)
can't read "x(1)": no such element in array
What happened is: a managed to set the element 1 of the local array x to
"foo", but NOT the local scalar variable 'x(1)' to foo. The latter is
the one that was linked to element 1 of the global array x.
|