Hello Monks,

I have the following subrutine to highlight all instances of a given word in a text widgets (this process is repeated x-times for the x-words I want to highlight. I use a regex in order to delimit the boundary of the words (only entire words should be highlighted). It works fine, until I try to add the -nocase flag...and here lies my problem

highlightText($TextWidget, \$term, 'selectedTerm', 'regexp'); sub highlightText { my($w, $string, $tag, $kind) = @_; my $stringw = $$string; return unless ref($string) && length($$string); my($current, $length) = ('1.0', 0); $stringw = qr/\b\Q$stringw\E\b/;#creating regex while (1) { $current = $w->search(-count => \$length, "-$kind", "-nocase", $st +ringw, $current, 'end');#here I the -nocase causes an issue last if not $current; $w->tagAdd($tag, $current, "$current + $length char"); $current = $w->index("$current + $length char"); } }

If I call $w->search without -nocase, my script works fine


In reply to Perl tk text -nocase by IB2017

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.