Reputation: 11
I searched for similar threads involving this error related to the use of "elseif" and double checked to make sure I wasn't making any of the same mistakes that were previously posted or discussed. Based on my research, I believe this code is accurate and formatted properly. Could there be a version issue and perhaps my company doesn't have the correct libraries or did I truly mess up the syntax?
The Error I'm receiving is:
[0:TEST] Tcl error:
msgId = message0
proc = 'X_EPIC_UROLOGY_OBR_xlate'
args = ''
result = 'wrong # args: extra words after "else" clause in "if" command'
errorInfo: '
wrong # args: extra words after "else" clause in "if" command
while executing
"if { [regexp {1184684789|1891756748|1356301840|1457541278|1275755076} $att_prov] == 1} {
set fieldList [lreplace $fieldList 7 7 $a..."
invoked from within
"if [cequal $segtype PV1] {
set fieldList [split $seg $field_sep]
if { [regexp {1184684789|189175..."
(procedure "X_EPIC_UROLOGY_OBR_xlate" line 166)
invoked from within
"X_EPIC_UROLOGY_OBR_xlate {MSGID message0} {CONTEXT sms_ib_data} {ARGS {}} {MODE run} {VERSION 3.0}"'
My Code:
if [cequal $segtype PV1] {
set fieldList [split $seg $field_sep]
if { [regexp {1184684789|1891756748|1356301840|1457541278|1275755076} $att_prov] == 1} {
set fieldList [lreplace $fieldList 7 7 $att_prov]
} elseif {
[regexp {1184684789|1891756748|1356301840|1457541278|1275755076} $ord_prov_obr] == 1} {
set fieldList [lreplace $fieldList 7 7 $ord_prov_obr]
} elseif {
[regexp {1184684789|1891756748|1356301840|1457541278|1275755076} $cc_prov] == 1} {
set fieldList [lreplace $fieldList 7 7 $cc_prov]
} elseif {
[regexp {1184684789|1891756748|1356301840|1457541278|1275755076} $ord_prov_orc] == 1} {
set fieldList [lreplace $fieldList 7 7 $ord_prov_orc]
} elseif {
[regexp {1184684789|1891756748|1356301840|1457541278|1275755076} $ref_prov] == 1} {
set fieldList [lreplace $fieldList 7 7 $ref_prov]
} else {
[regexp {1184684789|1891756748|1356301840|1457541278|1275755076} $cc_prov] == 1} {
set fieldList [lreplace $fieldList 7 7 $cc_prov]
}
}
Upvotes: 1
Views: 2646
Reputation: 247192
You have the answer to your syntax error. Now, a bit of code review.
You have a lot of cut'n'paste code in there. DRY:
if {[cequal $segtype PV1]} {
# ^.....................^ remember to brace the expression
set fieldList [split $seg $field_sep]
set pattern {1184684789|1891756748|1356301840|1457541278|1275755076}
foreach word [list $att_prov $ord_prov_obr $cc_prov $ord_prov_orc $ref_prov $cc_prov] {
if {[regexp $pattern $word]} {
set fieldList [lreplace $fieldList 7 7 $word]
break
}
}
}
It appears with the regexp command that you are validating that a word is in an allowed list of words. You don't want to get false positives, for example in case $att_prov equals "118". I'd take the regexp out of it, and just test for list membership which uses string equality
set allowed {1184684789 1891756748 1356301840 1457541278 1275755076}
foreach word [list $att_prov $ord_prov_obr $cc_prov $ord_prov_orc $ref_prov $cc_prov] {
if {$word in $allowed} {
set fieldList [lreplace $fieldList 7 7 $word]
break
}
}
Aside from choosing variable names that suit your domain better, I think this more clearly expresses your intent.
Upvotes: -1
Reputation: 5763
You have:
} else {
[regexp {1184684789|1891756748|1356301840|1457541278|1275755076} $cc_prov] == 1} {
set fieldList [lreplace $fieldList 7 7 $cc_prov]
}
This should be an elseif
.
Upvotes: 0
Reputation: 386342
The problem is your last "else". you have two "words" after it.
The way tcl see it is this:
} else { [regexp ...] == 1} {...}
^^^^^^^^^^^^^^^^^^^^ ^^^^^
word 1 word 2
The "extra word after else clause" is word 2, the {...}
part. After the else
you're only allowed to have a single "word" (tcl's definition of "word", not a literal word").
If this is truly an "else" (ie: do this if all of the other conditions fail"), you need to just remove all of word 1. If it's another condition, you need to change else
to elseif
so that it treats word 1 as an expression.
Upvotes: 2