TCL Error: can't set "::streamID(1,10,1)": variable isn't array

TCL Error: can't set "::streamID(1,10,1)": variable isn't array

我已经阅读了线程,Cant read variable, isnt array,我认为可能有某种关联,但我不知道如何关联。在以下 TCL 片段中,测试了三维数组 ::stream 并读取了一个值。该数组包含标量 ID 值。片段中的最后一行创建了一个错误

can't set "::streamId(1,10,1)": variable isn't array
    while executing
"set ::streamId($chas,$card,$port) $nextId"
    (procedure "getNextStreamId" line 28)

我将其解释为 $nextId 不是标量,不能放入 3 维标量数组中。我对错误的解释不正确吗?我非常有信心该数组包含标量值,所以我开始认为这里可能存在一些数据安全问题。

# get current streamId
if { [ catch {info exists $::streamId($chas,$card,$port)} ] == 0 } {
if {$::testEnv(verbose) >= $verbLevel} {
    logInfo [getProcName] "pre-existing streamId found for: \
        \n dutAndPort:  $dutAndPort \
        \n ixiaPort:    {$chas $card $port}\
        \n streamId:    $::streamId($chas,$card,$port) \
        \n incrementing to next one..."
}
set nextId [ mpexpr $::streamId($chas,$card,$port) + 1 ]
} else {
if {$::testEnv(verbose) >= 0} {
    logInfo [getProcName] "No pre-existing streamId found for: \
        \n\t dutAndPort:    $dutAndPort \
        \n\t ixiaPort:      {$chas $card $port}\
        \n\t setting to 1"
}
set nextId 1
}
set curId  [ mpexpr $nextId - 1 ]

set ::streamId($chas,$card,$port) $nextId

在您的代码中,我猜您想检查数组 ::streamId 是否具有索引 $chas,$card,$port

info exists $::streamId($chas,$card,$port)

这是不正确的。你应该使用

info exists ::streamId($chas,$card,$port)

即没有美元符号。那么只有if循环才能保证索引$chas,$card,$port.

的存在

然后,最后您尝试将索引 $chas,$card,$port 的值设置为 $nextId

set ::streamId($chas,$card,$port) $nextId

这是不正确的,因为它保留在索引$chas,$card,$port.

的变量存在检查的if循环之外

那么实际的错误消息是指存在一个名为 streamId 的标量变量这一事实。

% set ::streamId 1
1
% set ::streamId(1,10,1) 20
can't set "::streamId(1,10,1)": variable isn't array
%

确保您没有相同的变量名。