Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > bd5c3d824c3db63ffd9226c15941e6ad > files > 2010

mozart-1.4.0-1mdv2010.0.i586.rpm

<HTML><HEAD><TITLE>Tcl Built-In Commands - switch manual page</TITLE></HEAD><BODY>
<DL>
<DD><A HREF="switch.htm#M2" NAME="L862">NAME</A>
<DL><DD>switch - Evaluate one of several scripts, depending on a given value</DL>
<DD><A HREF="switch.htm#M3" NAME="L863">SYNOPSIS</A>
<DL>
<DD><B>switch </B>?<I>options</I>?<I> string pattern body </I>?<I>pattern body </I>...?
<DD><B>switch </B>?<I>options</I>?<I> string </I>{<I>pattern body </I>?<I>pattern body </I>...?}
</DL>
<DD><A HREF="switch.htm#M4" NAME="L864">DESCRIPTION</A>
<DL>
<DD><A HREF="switch.htm#M5" NAME="L865"><B>-exact</B></A>
<DD><A HREF="switch.htm#M6" NAME="L866"><B>-glob</B></A>
<DD><A HREF="switch.htm#M7" NAME="L867"><B>-regexp</B></A>
<DD><A HREF="switch.htm#M8" NAME="L868"><B>--</B></A>
</DL>
<DD><A HREF="switch.htm#M9" NAME="L869">KEYWORDS</A>
</DL><HR>
<H3><A NAME="M2">NAME</A></H3>
switch - Evaluate one of several scripts, depending on a given value
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>switch </B>?<I>options</I>?<I> string pattern body </I>?<I>pattern body </I>...?<BR>
<B>switch </B>?<I>options</I>?<I> string </I>{<I>pattern body </I>?<I>pattern body </I>...?}<BR>
<H3><A NAME="M4">DESCRIPTION</A></H3>
The <B>switch</B> command matches its <I>string</I> argument against each of
the <I>pattern</I> arguments in order.
As soon as it finds a <I>pattern</I> that matches <I>string</I> it
evaluates the following <I>body</I> argument by passing it recursively
to the Tcl interpreter and returns the result of that evaluation.
If the last <I>pattern</I> argument is <B>default</B> then it matches
anything.
If no <I>pattern</I> argument
matches <I>string</I> and no default is given, then the <B>switch</B>
command returns an empty string.
<P>
If the initial arguments to <B>switch</B> start with <B>-</B> then
they are treated as options.  The following options are
currently supported:
<P>
<DL>
<P><DT><A NAME="M5"><B>-exact</B></A><DD>
Use exact matching when comparing <I>string</I> to a pattern.  This
is the default.
<P><DT><A NAME="M6"><B>-glob</B></A><DD>
When matching <I>string</I> to the patterns, use glob-style matching
(i.e. the same as implemented by the <B><A HREF="../TclCmd/string.htm">string match</A></B> command).
<P><DT><A NAME="M7"><B>-regexp</B></A><DD>
When matching <I>string</I> to the patterns, use regular
expression matching
(i.e. the same as implemented by the <B><A HREF="../TclCmd/regexp.htm">regexp</A></B> command).
<P><DT><A NAME="M8"><B>--</B></A><DD>
Marks the end of options.  The argument following this one will
be treated as <I>string</I> even if it starts with a <B>-</B>.
<P></DL>
<P>
Two syntaxes are provided for the <I>pattern</I> and <I>body</I> 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 <I>pattern</I> arguments are in braces in the second form,
no command or variable substitutions are performed on them;  this makes
the behavior of the second form different than the first form in some
cases.
<P>
If a <I>body</I> is specified as ``<B>-</B>'' it means that the <I>body</I>
for the next pattern should also be used as the body for this
pattern (if the next pattern also has a body of ``<B>-</B>''
then the body after that is used, and so on).
This feature makes it possible to share a single <I>body</I> among
several patterns.
<P>
Below are some examples of <B>switch</B> commands:
<PRE><B>switch abc a - b {format 1} abc {format 2} default {format 3}</B></PRE>
will return <B>2</B>, 
<PRE><B>switch -regexp aaab {
	^a.*b$ -
	b {format 1}
	a* {format 2}
	default {format 3}
}</B></PRE>
will return <B>1</B>, and
<PRE><B>switch xyz {
	a
		-
	b
		{format 1}
	a*
		{format 2}
	default
		{format 3}
}</B></PRE>
will return <B>3</B>.

<H3><A NAME="M9">KEYWORDS</A></H3>
<A href="../Keywords/S.htm#switch">switch</A>, <A href="../Keywords/M.htm#match">match</A>, <A href="../Keywords/R.htm#regular expression">regular expression</A>
<HR><PRE>
<A HREF="../copyright.htm">Copyright</A> &#169; 1993 The Regents of the University of California.
<A HREF="../copyright.htm">Copyright</A> &#169; 1994-1996 Sun Microsystems, Inc.
<A HREF="../copyright.htm">Copyright</A> &#169; 1995-1997 Roger E. Critchlow Jr.</PRE>
</BODY></HTML>