in reply to Slicing a string on words

Err... I don't know what to suggest, because as far as I can make out it does work:
$window_start = 5; $window_size = 5; $text_body = "Please ignore all this text, this is the text wanted, pl +ease none of this text"; if ($window_start > 0) { $text_body =~ /\S+/g foreach 1..$window_start; $start_index = pos($text_body); } else { $start_index = 0; } $text_body =~ /\S+/g foreach 1..$window_size; $end_index = pos($text_body); $windowed_text = substr($text_body, $start_index, ($end_index - $start +_index)); print $windowed_text; #prints " this is the text wanted,"
You just gotta believe! If faith is not enough, then may I suggest you post the contents of your $vars?

By the way, you could alter your last line slightly to$windowed_text = substr($text_body, $start_index + 1, ($end_index - $start_index))- then you lose the leading space.

§ George Sherston

Replies are listed 'Best First'.
Re: Re: Slicing a string on words
by dstar (Scribe) on Aug 28, 2001 at 02:47 UTC
    See this? This is my head banging into the wall. Wall, meet head. Head, wall.

    Here's what the problem seems to be: when I tested it, it was with a short string and a window large enough that the string ended well before the end of the window. IE, a 20 word string with a 100 word window.

    Argh. I'm not sure where to go from here. Perhaps coffee is a good idea.

      The whiles in my update should bail out when they run out of matches.

      You may test on some input but it seems to take equal or less than window just fine