We don't bite newbies here... much | |
PerlMonks |
Re^3: splitting text into lines -- code -> regexby hawtin (Prior) |
on Jul 12, 2004 at 21:43 UTC ( [id://373743]=note: print w/replies, xml ) | Need Help?? |
That might present a problem, as some spaces are actual delimiters, and others are going to be literal text. If you treat both the same way (split on plain spaces and reassemble all the "words"), you may end up splitting words that happened to span a 27-char limit.
The way the problem was stated it seemed to me that you can guarantee that each 'line' ends in a space. If that is correct then you know each 'line' is the concatenation of a number of 'chunks', that is no 'chunk' can belong to two different lines. Is that not correct? That is not, of course, to say that every space is the delimiter of a 'line' (otherwise it would be simple). My code did take into account the fact that spaces have two different meanings. While I did forget to allow for adding one for the extra space a working version is quite close to my original code:
Gives
If however my assumption about spaces at the end of each line is wrong (for example if there could be words that are longer than 27 characters without a space) then a simple if statement will take care of that, something like:
It is true that this is a more simplistic approach than using a "negative lookahead assertion", but there again I don't know how one of them works :-)
In Section
Seekers of Perl Wisdom
|
|