Reputation: 1006
Simple question, TCL gives me "premature end of expression" because the last param of the ternary expression is an empty string. If it is anything else then it works ok. Can I use an empty string here?
set y 5
set x [expr ($y > 1) ? 1 : ""]
Upvotes: 3
Views: 2842
Reputation: 13252
You should always give expr
a single, complete expression, wrapped in braces, as argument. This avoids a whole slew of problems, including this one.
expr {$y > 1 ? 1 : ""}
The problem is that expr
concatenates its arguments to get an expression. The invocation concat $y > 1 ? 1 : ""
gives the string "5 > 1 ? 1 : ", which can't be parsed by expr
.
Upvotes: 10