| |||||||||||
switch and variables - no comparison/matching? Posted by balk (balk), 20 July 2007 Love the site! I do have a question that is troubling me. Is there a way to use a switch statement and have it look at the value of a variable for the comparison? In the following switch statement, the switch doesn't recognize or match with $SegOne. Even though I get SegmentType as MSH, it never hits the SegOne case. I don't want to hardcode MSH in the switch as that would defeat the purpose of using a variable. Any thoughts? I'd appreciate it. Thanks, Nate. set SegOne MSH set SegmentType [lindex $seg 0] switch -exact -- $SegmentType { $SegOne { puts stdout "Inside with $SegOne" } default { puts stdout "Outside with $SegmentType" } } Posted by admin (Graham Ellis), 20 July 2007 Yes, Nate - you can. The problem is the { on the end of the switch line which defines all the rest as a deferred block, so supresses the interpretation of the $SegOne.You're probably going to ask me "so what should I do / how should I write it". Yikes - replace the outer { and } with " and " and add \ protection on every new line and " within ... that's not trivial the first time! Posted by balk (balk), 20 July 2007 Wow, that is crazy! I tried it and it works. I would've never got that one on my own. It's nice that this Tcl forum actually gets some action and is being used.Again, thank you for the response and your time. It is appreciated. Nate. This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
Other Forum Posts Follow us on ... | ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |