infor.com
concierge
infor u
developer portal
documentation central
customer center
Posts
Categories
Groups
ERPs
CSD
FSM/HRT
LN
M3
Syteline/ CSI
Hubs
Developer
Healthcare
Hospitality
Public Sector
Onboarding
Release Center
CloudSuites
Aerospace & Defense (LN)
Automotive (LN)
Chemicals (M3)
Corporate (FSM/HRT)
Distribution (Sx.e/CSD)
Distribution Enterprise (M3)
Engineering & Construction (LN)
Fashion (M3)
Food & Beverage (M3)
Healthcare (FSM/HRT)
Industrial (Syteline/CSI)
Industrial Enterprise (LN)
Manufacturing (M3)
Public Sector (FSM/HRT)
Solutions
Supply Chain Management (SCM)
Human Capital Management (HCM)
Events
Groups
User Groups
Your Groups
About
Email Community Support
Infor News
Migrated Forums
Home
Clovertech
Clovertech Archive
Cloverleaf
problem with array
Gene Millard
I am setting an array in my tcl.
set FT($index1) $segment
index1 equals the below
2021020186900
2021020186901
The index ending in 900 goes into the array first
When I read the array using the code below I get the information from 2021020186901 first which makes the segments out of sequence.
set srch [array startsearch FT]
while {[array anymore FT $srch]} {
set key [array nextelement FT $srch]
set segment2 $FT($key)
lappend line3 $segment2
}
How do I get the information out in the order I put it in?
Gene Millard
Find more posts tagged with
Clovertech
Comments
Jeff Dinsmore
It would seem that "array nextelement" doesn't necessarily return keys in the order they were written.
The same is true for "array names", so that's not surprising.
If your array keys are consistent date/time stamps, you can just sort them with lsort.
foreach key [lsort [array names FT]] {
<do stuff with $FT($key) here>
}
Gene Millard
Thank you that worked.
Gene Millard
The Guthrie Clinic
Charlie Bursell
FYI
Array keys are not ordered. It isn't straight-forward to get values out of an array in the same order that they were set. One common alternative is to get the names and then order them. Internally, Tcl uses a hash table to implement an array.
You could always use the dict command if there is no logical way to order an array.