Reputation: 1036
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: 2856
Reputation: 13282
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