in reply to Re: regexp pattern match help?
in thread regexp pattern match help?

Ok cool, good to know. I think I have a decent way of accomplishing this but need a good way to set the length of string to be colored to the whole commented string. Here is what I have so far:
my $word = '#'; my $next = "1.0"; while (my $from = $t->search(-regexp, "\\B$word\\B", $next +, "end")) { my @comment = split(/#/, $_); #print "\$comment[0] equals ",$comment[0],"\n"; #print "\$comment[1] equals ",$comment[1],"\n"; if ($comment[1]) { my $word_len = length $comment[1] + length $word; }else{ my $word_len = length $comment[0] + length $word; } print $word; print $word_len; $next = "$from + $word_len chars"; $t->tagAdd("orange", $from, $next); $t->tagAdd("bold", $from, $next); }
I decided to use split to accomplish what I wanted but for some reason on each string the length only ends up being 5 so the first 5 characters of the commented strings gets colored. How can I color the whole comment once the comment character is found. Oh and am I searching for the comment symbol the best way using the "B"?

Replies are listed 'Best First'.
Re: Re: Re: regexp pattern match help?
by ysth (Canon) on Dec 03, 2003 at 07:35 UTC
    You have two problems there.

    The my $word_len's you declare inside the if statement are not visible outside the if statement, so you are seeing some other $word_len, either a global variable or a lexical in an outer scope.

    And you have a precedence problem. You are doing like length($comment[1] + length $word); make it like length($comment[1]) + length $word instead.