DISCLAIMER: This is UNTESTED ... It's just something to try... $OrgLine = "adshe ms0e sad qweoic,m qwod x0 vndu qiudb siu .... ";
While length of $OrgLine > 70 { Match on =~ /(.{0,70})\s/ Print $1 Remove $1 from $OrgLine ; } Print remainder of $OrgLine; So, the regex would return (again, this is untested) $1 with up to 70 characters that terminated with a white space. Just a thought ... -rjf > -----Original Message----- > From: M z [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, March 06, 2002 10:58 > To: [EMAIL PROTECTED] > Subject: help me with a better backstepper? > > > Hi > > I've written a little program to analyze lines that > are longer than 70 characters, and if so, break at > position 70 (if it is whitespace), if not whitespace > (i.e. is in the middle of a word) it steps back to the > first whitespace and breaks there. > > However, I think there is probably a better way to do > this. Can someone either suggest an alternate route > or improve this snippet? > > ps. if you do suggest something cryptic, please detail > for me, as I am still new!!! thanks > > while(<F>) { > chomp; > if (length $_ < 70){ > print F1 "$_\n"; > } > > else { > > split(//, $_); > if ($_[69] eq " ") { > s/^(.{69}) (.*)$/$1\n+ $2\n/; > print F1; > } > elsif($_[69] ne " " && $_[68] eq " ") > { > @_ = (); > split(//, $_); > s/^(.{68}) (.*)$/$1\n+ $2\n/; > print F1 $_; > } > elsif($_[69] ne " " && $_[68] ne " "&& > $_[67] eq " ") { > @_ = (); > split(//, $_); > s/^(.{67}) (.*)$/$1\n+ $2\n/; > print F1 $_; > } > > ..... > > # this is the strategy to back up 30 spaces > eventually, > but I don't want to have 30 elsif statements, although > this works, it seems that a more experienced perl > programmer could write this with much less code... > > __________________________________________________ > Do You Yahoo!? > Try FREE Yahoo! Mail - the world's greatest free email! http://mail.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]