Hi,
Here's my changed code(part of it).

foreach $mitem(@missing) { $result=$t->search(-forwards,"**",'end'); #print"\nThe start pos of the pattern:"; #print "\n$result"; #1.4 $start=$result+.2; #print "\n$start"; #1.6 $x=substr($start,0,1);# integer $y = substr($start,2,2);# integer #print $y; $z=$y + 1; #print $z; for( 1 .. 10 ) { $start_pt="$x.$y"; # string #print " $start_pt "; $y++; $end_pt="$x.$z"; # string #print " $end_pt "; $z++; $char_read=$t->get("$start_pt","$end_pt"); #print "\nThe charcter:"; #print "\n$char_read" push @chars,$char_read; #print "\nThe word:"; #print "\n@chars"; } #$x=1; #$y=6; #$l=length(@chars); #$fract=(($y+$l)-1); #$wd_end=$x.$fract; #$t->tagConfigure("wrong",-foreground=>"red"); #$t->tagAdd("wrong","$start","$wd_end"); #print "\n@chars"; }

I'm using the above code inside a subroutine, which is called when a button is clicked in a Tk text widget.

This for loop: for( 1 .. 10 ) {

needs to read the word immediately next to the **
(the first time this pattern is found by $t->search)
but here this loop reads two words.The loop should stop
reading characters once it encounters a whitespace.
I've tried putting a do loop outside the for loop like this

do { $white_space=" "; for( 1 .. 10 ) { ..... stuff inside for loop. ..... } } until ($char_read eq $white_space);

but this code just hangs when executed(Argh!).

What is the problem here?

Each time the outer foreach loop is executed,
the search function should look for the first
occurence of ** in the widget window.The word next
to the **'s needs to be read, and it's font color set to
red, using a tag,and the two **'s in front of the word
deleted.

The next time around the foreach loop the next ocurrence
of ** should be located, the next word extracted ,it's
colour changed, the **'s deleted, and so on.I hope this
works(!).

e.g. **word **nextword

In the above example I need the for loop to read
'word' and stop once a whitespace is encountered.
The 'nextword' should be taken care of the next time
the foreach loop runs.

Of course we can read a word like this too instead
of char by char:

$char_read=$t->get("$start_pt","$start_pt wordend");

But I'm working on text that is in another language(font)
and the 'wordend' modifier does not work in my case, though
it works fine with text in an English font(I tried it)
So all the trouble.
Any help would be appreciated.
Thanx.

In reply to Re: Re: Simple loop question by perl_seeker
in thread Simple loop question by perl_seeker

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.