Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How do I wrap long lines at a fixed width, ignoring word boundaries?

by davorg (Chancellor)
on Jan 12, 2001 at 22:27 UTC ( [id://51426]=note: print w/replies, xml ) Need Help??


in reply to How do I wrap long lines at a fixed width, ignoring word boundaries?

sub fixedwidth_linebreaks { my( $str, $width ) = @_; my $newstr; while ( $str ) { $newstr .= substr( $str, 0, $width, '' )."\n"; } $newstr } $str = fixedwidth_linebreaks( $str, 128 );

Note that this adds a newline onto the last segment, even if it's shorter than the specified width.

  • Comment on Re: How do I wrap long lines at a fixed width, ignoring word boundaries?
  • Download Code

Log In?
Username:
Password:

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

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

    No recent polls found