1mNAME0m
       switch - Evaluate one of several scripts, depending on a given value

1mSYNOPSIS0m
       1mswitch 22m?4moptions24m? 4mstring24m 4mpattern24m 4mbody24m ?4mpattern24m 4mbody24m ...?

       1mswitch 22m?4moptions24m? 4mstring24m {4mpattern24m 4mbody24m ?4mpattern24m 4mbody24m ...?}


1mDESCRIPTION0m
       The 1mswitch 22mcommand matches its 4mstring24m argument against each of the 4mpat-0m
       4mtern24m arguments in order.  As soon as it finds a  4mpattern24m  that  matches
       4mstring24m  it  evaluates  the following 4mbody24m argument by passing it recur-
       sively to the Tcl interpreter and returns the result  of  that  evalua-
       tion.   If  the  last  4mpattern24m argument is 1mdefault 22mthen it matches any-
       thing.  If no 4mpattern24m argument matches 4mstring24m and no default is  given,
       then the 1mswitch 22mcommand returns an empty string.

       If  the  initial arguments to 1mswitch 22mstart with 1m- 22mthen they are treated
       as options.  The following options are currently supported:

       1m-exact    22mUse exact matching when comparing 4mstring24m to a pattern.   This
                 is the default.

       1m-glob     22mWhen matching 4mstring24m to the patterns, use glob-style matching
                 (i.e. the same as implemented by the 1mstring match 22mcommand).

       1m-regexp   22mWhen matching 4mstring24m to the patterns, use regular  expression
                 matching (as described in the 1mre_syntax 22mreference page).

       1m--        22mMarks  the  end  of options.  The argument following this one
                 will be treated as 4mstring24m even if it starts with a 1m-22m.

       Two syntaxes are provided for the  4mpattern24m  and  4mbody24m  arguments.   The
       first  uses  a separate argument for each of the patterns and commands;
       this form is convenient if substitutions are desired  on  some  of  the
       patterns  or  commands.  The second form places all of the patterns and
       commands together into a single argument; the argument must have proper
       list  structure,  with  the elements of the list being the patterns and
       commands.  The second form makes it easy to construct multi-line switch
       commands, since the braces around the whole list make it unnecessary to
       include a backslash at the end of each line.  Since the  4mpattern24m  argu-
       ments  are in braces in the second form, no command or variable substi-
       tutions are performed on them;  this makes the behavior of  the  second
       form different than the first form in some cases.

       If  a  4mbody24m  is  specified as ``1m-22m'' it means that the 4mbody24m for the next
       pattern should also be used as the body for this pattern (if  the  next
       pattern  also has a body of ``1m-22m'' then the body after that is used, and
       so on).  This feature makes it possible to share a  single  4mbody24m  among
       several patterns.

       Beware  of  how you place comments in 1mswitch 22mcommands.  Comments should
       only be placed 1minside 22mthe execution body of one of  the  patterns,  and
       not intermingled with the patterns.

       Below are some examples of 1mswitch 22mcommands:
              1mswitch abc a - b {format 1} abc {format 2} default {format 3}0m
       will return 1m222m,
              1mswitch -regexp aaab {0m
                1m^a.*b$ -0m
                1mb {format 1}0m
                1ma* {format 2}0m
                1mdefault {format 3}0m
              1m}0m
       will return 1m122m, and
              1mswitch xyz {0m
                1ma0m
                   1m-0m
                1mb0m
                   1m{0m
                   1m# Correct Comment Placement0m
                   1mformat 10m
                1m}0m
                1ma*0m
                   1m{format 2}0m
                1mdefault0m
                   1m{format 3}0m
              1m}0m
       will return 1m322m.


1mSEE ALSO0m
       for(n), if(n), regexp(n)


1mKEYWORDS0m
