The problem is that the order in which I “insert” elements into the array changes during the execution of the script.
Here is a quick reproduction of the problem:
#!/bin/bash
exec /home/binops/afse/eer/eer_SPI-7.3.1/tclsh "$0" "$@"
proc myProc { theArray } {
upvar $theArray theArrayInside
parray theArrayInside
puts "------"
foreach { key value } [array get theArrayInside] {
puts "$key => $value"
}
}
set myArray(AQHI) AQHI
set myArray(O3) 1
set myArray(NO2) 2
set myArray(PM2.5) 3
parray myArray
puts "------"
myProc myArray
Output:
myArray(AQHI) = AQHI
myArray(NO2) = 2
myArray(O3) = 1
myArray(PM2.5) = 3
------
theArrayInside(AQHI) = AQHI
theArrayInside(NO2) = 2
theArrayInside(O3) = 1
theArrayInside(PM2.5) = 3
------
PM2.5 => 3
O3 => 1
NO2 => 2
AQHI => AQHI
Note. I did not use shared keys like A, B, C and common values like 1, 2, 3, as you might expect. This is because the order is not corrupted by these generalized keys / values. Perhaps this will help identify the problem.
Also note that the initial order (AQHI, O3, NO2, PM2.5) is lost even on the first call parray(now the order of AQHI, NO2, O3, PM2.5, sorted alphabetically?). Then it changes again when called array get ...(reverse?)
, : , ?