perl_seeker has asked for the wisdom of the Perl Monks concerning the following question:
Consider the for loopforeach $mitem(@missing) { #print"\n$mitem"; $result=$t->search(-forwards,"**",'end'); #print"\nThe start pos of the pattern:"; #print "\n$result"; #1.4 ($x, $y) = split '\.' => $result; $y += 2; #print "\n$x"; #print "\n$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"; last if $char_read eq /\s/; } }
This loop reads a word at a particular position from a Tk text widget char by char.I need the for loop to stop if $char_read is a white space i.e. at the end of the word. This line in the code is not working,and the loop reads the first word , the whitespaces next to it and some characters of the next word too. last if $char_read eq /\s/; I've tried using the unless and until modifiers after the for loop but I keep getting a syntax error.for( 1 .. 10 )
Something like
I've tried putting a do loop (with an until modifier) around the for loop,this makes the code just hang.white_space=" "; #for loop stuff until $char_read eq white_space;
To be noted is that this for loop is inside a foreach loop This thing is really driving me crazy.What is the problem here?Any solutions?
Thanx, :)
Edit by tye, remove rampant BR tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex and loop question
by MidLifeXis (Monsignor) on Aug 20, 2003 at 10:23 UTC | |
by perl_seeker (Scribe) on Aug 22, 2003 at 09:56 UTC | |
|
Re: Regex and loop question
by hmerrill (Friar) on Aug 20, 2003 at 13:54 UTC | |
by perl_seeker (Scribe) on Aug 22, 2003 at 10:04 UTC | |
|
Re: Regex and loop question
by CombatSquirrel (Hermit) on Aug 20, 2003 at 12:15 UTC | |
by perl_seeker (Scribe) on Aug 22, 2003 at 10:18 UTC |