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