Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How can I split a line close to a certain length, but on a word boundary?

by poznick (Initiate)
on Apr 24, 2000 at 21:41 UTC ( [id://8730]=note: print w/replies, xml ) Need Help??


in reply to How can I split a line on word boundaries closest to a certain length?

I ended up using:
$rest = $messagebody;
@text=();
while($rest ne '') {
    $rest =~ /(.{1,140}\W)/ms;
    push @text, $1;
    $rest = $';
}
Text::Wrap doesn't provide the desired behavior, unless I were to do a tr/// to translate all the newlines into some strange character, do the wrap, and then tr the strange characters back to newlines. This way seemed a little cleaner.
  • Comment on Re: How can I split a line close to a certain length, but on a word boundary?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://8730]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2024-04-23 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found