Skip to Main Content
Learning Perl/Tk
book

Learning Perl/Tk

by Nancy Walsh
January 1999
Beginner content levelBeginner
373 pages
9h 43m
English
O'Reilly Media, Inc.
Content preview from Learning Perl/Tk

8.14. Searching the Contents of a Text Widget

You can use the search method to search the text widget for a pattern or regular expression. The search method takes some optional switches, the pattern to search for, and an index at which to start searching:

$index = $text->search([switches], pattern, index, [ stopindex ])

If a match is made, the index returned will point to the first character in the match. If no match is made, an empty string is returned.

The possible switches are:

-forwards

Tells searchto search forward through the text widget starting at index. This is the default.

-backwards

Tells searchto search backward through the text widget starting at the character before index.

-exact

The pattern must match the text exactly. This is the default.

-regexp

The patternwill be considered as a regular expression.

-nocase

Ignores case between pattern and the text within the text widget.

-count => varname

varname is a pointer to a variable (i.e., \$variable). The number of characters matched will be stored within that variable.

--

This option does nothing except force the next argument to be taken as the pattern even if the next string starts with a "-".

Here is a simple example of using search:

$result = $text->search(-backwards, "find me", 'end');

$location = $text->search(-nocase, "SWITCHES", "1.0");
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl/Tk

Mastering Perl/Tk

Stephen Lidie, Nancy Walsh

Publisher Resources

ISBN: 1565923146Supplemental ContentCatalog PageErrata