in reply to Splitting SPICE lines on 'word' boundries closest to a certain length
the condition for exiting the while loop -- $rest eq '' -- will never be met. The easiest fix (involving the smallest change to the existing code) would be:$rest = "+ " . $';
or something equivalent. Personally, though, I tend to prefer (r)index and substr for this sort of problem -- something like this (using index, because you seem to be willing to accept longer strings when looking for a place to break):$rest = ( $' ) ? "+ $'" : '';
while ( length($rest) > 25 ) { my $break = index( $rest, ' ', 25 ); last if ( $break < 0 ); # no more spaces to break on push @text, substr( $rest, 0, $break ); $rest = '+ ' . substr( $rest, $break ); } push @text, $rest if ( length( $rest ));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Splitting SPICE lines on 'word' boundries closest to a certain length
by gcmandrake (Novice) on Mar 23, 2004 at 17:19 UTC |