Homepage › Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › Iterating through table instead of using switch statement
- This topic has 10 replies, 6 voices, and was last updated 15 years, 5 months ago by Richard Hart.
-
CreatorTopic
-
May 14, 2009 at 4:22 pm #50869Nate KruseParticipant
All, Just bouncing a thought of the board. We currently have a tcl script with something like 75 values in a switch statement. I
-
CreatorTopic
-
AuthorReplies
-
-
May 14, 2009 at 4:48 pm #67845Jim KosloskeyParticipant
Nate,
Why not put the value you are looking for in the ‘IN’ column and what you want to do when it matches in the ‘OUT’ column.
Like this:
IN OUT
STAPHYLOCOCCUSAUREUS DE-14117|Staphylococcal disease, invasive|700043|YES
CLOSTRIDIUMBOTULINUM L-14118|Botulism|700002|YES
Then simply match $OBXsave to the IN column with hcitbllookup and do your work with the OUT Column.
email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.
-
May 14, 2009 at 6:53 pm #67846Nate KruseParticipant
Jim,
I am under the assumption that I can’t do a contains type of lookup in the table. My problem is is that OBX5save might have more text than just the word I’m looking for. So lets say OBX5save is set to “Encountered STAPHYLOCOCCUSAUREUS value”. Then the IN would fail to find it…correct?
Nate.
-
May 14, 2009 at 7:34 pm #67847Steve CarterParticipant
Nate,
The other option that you have is to load the table into an inboundList and outboundList. You can then utilize an ‘lsearch’ to find your value in the inboundList and use the returned index to find the element in the outboundList. If it returns ‘-1’, then you know it’s not there.
The other ‘benefit’, if you call it that, is that the table becomes dynamic and you don’t have to bounce/purge cache when you modify the table. It gets loaded everytime the code is executed.
Hope this helps.
Steve
-
May 15, 2009 at 12:59 pm #67848Nate KruseParticipant
Steve,
I’ve never used the approach of loading a table into a list. Do you have a sample of how one loads a table into a list?
Thanks for the responses so far.
Nate.
-
May 15, 2009 at 1:48 pm #67849Keith McLeodParticipant
How about treating your OBX:5 as a list and foreaching it through the table for a non default result.
-
May 15, 2009 at 2:56 pm #67850Steve CarterParticipant
Try this out:
#! /appData/local/bin/hcitcl
global HciRoot
set tableName “$HciRoot/Tables/ndcTblRoute.tbl”
set tableLines [split [read_file $tableName] n]
if { [lsearch $tableLines “revdflt=*”] == -1 } {
set tableStart [lsearch $tableLines “dflt=*”]
} else {
set tableStart [lsearch $tableLines “revdflt=*”]
}
incr tableStart 2
set tableLines [lrange $tableLines $tableStart end]
set index 0
while {$index < [llength $tableLines]} {
lappend listInbound [lindex $tableLines $index]
incr index
lappend listOutbound [lindex $tableLines $index]
incr index 2
}
puts “inbound: $listInbound”
puts “noutbound: $listOutbound”
-
May 15, 2009 at 7:06 pm #67851Abe RastkarParticipant
The tcl script is a goo idea.
I have the same script as a proc except my proc creates a keyed list where the input to the table is the key and the value of the table entry is the keyled list value.
-
May 15, 2009 at 8:05 pm #67852Steve CarterParticipant
The keyed list works well on a uni-directional table. A regular works better on a bi-directional table as you can search either side and grab the corresponding entry on the other.
-
May 15, 2009 at 8:36 pm #67853Abe RastkarParticipant
Good point, Steve
Abe
Steve Carter wrote:The keyed list works well on a uni-directional table.
-
May 18, 2009 at 6:56 am #67854Richard HartParticipant
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
}
-
-
AuthorReplies
- The forum ‘Cloverleaf’ is closed to new topics and replies.