Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Perl tk text -nocase

by IB2017 (Pilgrim)
on Apr 21, 2020 at 22:12 UTC ( [id://11115877]=perlquestion: print w/replies, xml ) Need Help??

IB2017 has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Perl tk text -nocase -regex
by IB2017 (Pilgrim) on Apr 21, 2020 at 22:19 UTC

    Solved. It works perfectly fine. I had some problems in the rest of the script. Okay. Time for a break.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11115877]
Approved by Paladin
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 16:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found