:)Hello,
it seems a bit silly to be asking this,but anyway consider this bit of code:
foreach $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/; } }
Consider the for loop
for( 1 .. 10 )
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.

Something like

white_space=" "; #for loop stuff until $char_read eq white_space;
I've tried putting a do loop (with an until modifier) around the for loop,this makes the code just hang.

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


In reply to Regex and 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.