We use arrays as tables extensively. In most cases, these are one-off, in some cases we get the users to maintain a spreadsheet and then simply process this to generate the array ‘table’ contents, so we don’t manually change the tables.
Some of the LAB test translation ‘tables’ contain more than 1000 entries!
eg
proc ReligionFn {aCode} {
# make the array global, so it is always available
global ReligionFnArray
#
# Initialise if applicable
#
if {[array exists ReligionFnArray] == 0} {
set ReligionFnArray(4SQ) {FOUR SQUARE}
set ReligionFnArray(AGN) {AGNOSTIC}
set ReligionFnArray(ANG) {ANGLICAN}
…
set ReligionFnArray(UN) {UNKNOWN}
set ReligionFnArray(UNI) {UNITARIAN}
set ReligionFnArray(WIC) {WICCIAN}
}
#
# set the return variable to the default, in this case the original
#
set myText $aCode
#
# Make sure we don’t fall over if there is NO data!
# Set the array id and go for it
#
catch {set myText $ReligionFnArray($aCode)}
#
# return the data from the array
#
return $myText
}