What are my options for variable expansion in switch cases? It seems to me that in the following code, when i visit http://example.com/bar/test, I should get “you found foo.” for my page content. In practice, this isn’t the case. What do I need to do to have the variable $foo expanded inside the switch?
Thanks.
when HTTP_REQUEST {
set foo "bar"
switch -glob -- [URI::decode [HTTP::uri]] {
"/$foo/*" { HTTP::respond 200 content "you found foo." }
}
}
What the heck?!?! Now that I read the official TCL doc closely (http://www.tcl.tk/man/tcl8.4/TclCmd/switch.htm), the first example does explicitly state that variables can be used with the syntax used in your second example. But what’s up with the first example - how did you come up with that one?
how did you come up with that one?i remember brace and double quote is interchangeable (except variable substitution) but honestly i forgot where i remember the 1st example form. i might mix it up in my mind. it may not be indeed correct. sorry about that. ^ ^