I have two questions:
In one of my tcl functions an array is declared and initialized as follows:
foreach port $StcPorts {
set dutport [lindex $DutPortsTmp $i]
set STCPort($dutport) [list 0 [lindex [lindex $cardlist $port] 0] [lindex [lindex $cardlist $port] 1]]
}
This is pretty confusing to me since I am new to tcl. Please help me to understand the above code on STCPort creation.
Question 2:
In the same file, STCPort is being used like this:
foreach dutport $DutPortsTmp {
set slot [lindex $STCPort($dutport) 1]
set port [lindex $STCPort($dutport) 2]
set hPort [stc::create port -under $hProject -location //$stcipaddress/$slot/$port -useDefaultHost False ]
lappend STCPort($dutport) $hPort
}
I have sourced this file and my requirement is to get the hPort value in another function residing in another file and work on it. Below is the function d_stc:
proc d_stc {args} {
global DutPorts STCPort
upvar 1 $STCPort _STCPort
#I am trying to get hPort by array index below:
foreach DutPort $DutPorts {
set card [lindex $_STCPort($DutPort) 1]
set port [lindex $_STCport($DutPort) 2]
set hport [lindex $_STCPort($DutPort) 3]
}
And, I am getting the following error:
can't read "STCPort": variable is array
while executing
"upvar 1 $STCPort _STCPort"
(procedure "d_stc" line 3)
I have used global to access the array in this function. But, where I am going wrong?
Thanks,