Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stopping the interpretor

Status
Not open for further replies.

tomdagliusa

Programmer
May 31, 2000
34
US
I have a switch where I am getting interpretation, but don't want to:

gist of code:

switch -glob -- $cmd {
"read" {blahblah}
"write" {other}
"no*" {
"no read" {no blahblah}
"no write" {no other}
}
}

When I run the code, I get "no read" failing as an
invalid command name.

I'm not sure how to un-bracket this so the interpreter doesn't kick in.

???,
Tom
 
The syntax of your switch command is not correct:
Code:
  swith -glob -- $cmd   {
    read    { ... }
    write   { ... }
    "no r*" { ... }
    "no w*" { ... }
    default { error "..." }
  }
There is only one level of switch cases.

HTH

ulis
 
Ulis,

I was trying to group all the no commands under one switch argument without having to make an entry for each. Is there a way to do that?

Tom
 
Ulis,

I did a version of what you suggested:

switch -glob -- $cmd {
"a" {}
"b" {}
"c" {}
"x" {}
"y" {}
"z" {}
"no a*" -
"no b*" -
"no c*" {...}
"no x*" -
"no y*" -
"no z*" {...}
}

Thanks for your help.
Tom
 
Tom,

I don't believe there is a way to do what you
originally wanted with the tcl switch construct.

I am curious though. In what languages are you
able to do something like that? I've never seen
anything like it before.
 
HI Marsd,

With a question like that, you give me much more
programming credit than I deserve. Ulis was right,
it was bad coding.

Tom
 
I think it's a pretty neat idea..but you win. ;-)
 
What you want is:
Code:
  swith -glob -- $cmd   {
    read    { ... }
    write   { ... }
    "no r*" -
    "no w*" { ... }
    default { error "..." }
  }
A hyphen after the case string tells switch to take the next following body.

From the switch page of the Tcl Manual:
If a body is specified as ``-'' it means that the body for the next pattern should also be used as the body for this pattern (if the next pattern also has a body of ``-'' then the body after that is used, and so on). This feature makes it possible to share a single body among several patterns.

HTH

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top