in reply to Re: Re: Coloring text using TK?
in thread Coloring text using TK?

Ok I actually found a way to shorten the code and combine multiple words into an array. It does not speed up the text coloring or parsing but it does not slow it down either. It is the exact same speed just less code then writing out every single word and corresponding parsing code. Here it is:
my @words = ("sub", "if", "elsif", "else", "my", "use"); foreach my $word (@words) { my $word_len = length $word; my $next = "1.0"; while (my $from = $t->search(-regexp, "\\b$word\\b", $n +ext, "end")) { $next = "$from + $word_len chars"; $t->tagAdd("blue", $from, $next); $t->tagAdd("bold", $from, $next); } }