in reply to Slicing a string on words
It seems you want a window x words big?
@words=$text_body =~ /(\S+)/g; #compute $start and $end $newtext=join(" ",@words[$start..$end]);
Update:Without copying. Note: I could not get the foreach deal to work at all so had to use while with a counter.
# $start and $window $i++ while($i<$start && /(\S+\s+)/g); $i=0; while(/\G(\S+\s+)/g && $i<$window_length) { $newtext .= "$1"; $i++; }
Note also: Two types of while. Probably should pick one you like the best and standardize on that.
This skips the $start number of words and the assigns $window_length words to $newtext preserving whitespace
Another Update: $start of 0 was not working but reversing the tests in the first while fixes that.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Slicing a string on words
by dstar (Scribe) on Aug 28, 2001 at 02:39 UTC | |
|
Re: Re: Slicing a string on words
by dstar (Scribe) on Aug 29, 2001 at 20:31 UTC | |
by dga (Hermit) on Aug 29, 2001 at 22:02 UTC |