tsv lsearch
Finds an element of a list in a shared array.
tsv::lsearch ARRAY ELEMENT ?MODE? PATTERN
Description
The command tsv::lsearch searches the list in the element for PATTERN with lsearch, and gives the index of the first match or -1. MODE is one option of lsearch, such as -exact, -glob (the default), -regexp, -nocase, -all, or -inline.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| ARRAY | array name | required | The name of the shared array. |
| ELEMENT | string | required | The name of the element. |
| MODE | an option of lsearch | -glob | How to match. |
| PATTERN | glob pattern, value, or regular expression | required | What to find. |
Returns
The result of lsearch: an index or -1, or a list with -all or -inline.
Examples
% tsv::set l x {apple box ant}
> tsv::lsearch l x b*
1
% tsv::set l x {apple box ant}
> tsv::lsearch l x -exact a*
-1
% tsv::set l x {a b a}
> tsv::lsearch l x -all a
0 2
Errors
% tsv::set l x {a b}
> tsv::lsearch l x
wrong # args: should be "tsv::lsearch l x ?mode? pattern"
-errorcode TCL WRONGARGS
# Tcl 9.1 only
% tsv::set l x {a b}
> tsv::lsearch l x -bogus a
bad option "-bogus": must be -all, -ascii, -bisect, -decreasing, -dictionary, -exact, -glob, -increasing, -index, -inline, -integer, -nocase, -not, -real, -regexp, -sorted, -start, -stride, or -subindices
-errorcode TCL LOOKUP INDEX option -bogus
# Tcl 8.6 only
% tsv::set l x {a b}
> tsv::lsearch l x -bogus a
bad option "-bogus": must be -all, -ascii, -bisect, -decreasing, -dictionary, -exact, -glob, -increasing, -index, -inline, -integer, -nocase, -not, -real, -regexp, -sorted, -start, or -subindices
-errorcode TCL LOOKUP INDEX option -bogus
Tcl 8.6 and Tcl 9.1
- The message of a bad MODE lists the options of
lsearchof the release, and Tcl 9.1 has-stride.
Facts
- Capability
thread. A new interpreter does not have it until the host turns it on.- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1