O'Reilly logo

Practical Programming in Tcl & Tk, Third Edition by Brent B. Welch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Searching Lists: lsearch

lsearch returns the index of a value in the list, or -1 if it is not present. lsearch supports pattern matching in its search. Glob-style pattern matching is the default, and this can be disabled with the -exact flag. The semantics of glob pattern matching is described in Chapter 4. The -regexp option lets you specify the list value with a regular expression. Regular expressions are described in Chapter 11. In the following example, the glob pattern l* matches the value list.

lsearch {here is a list}l*
=> 3
					

Example 5-6 uses lreplace and lsearch to delete a list element by value. The value is found with lsearch. The value is removed with an lreplace that does not specify any replacement list elements:

Example 5-6 Deleting ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required