in reply to How to wrap text to a maximum width of 70 characters per line?

appendum: following this Smart Substrings node, let me just say that I'd combine my answer with that one, given the chance again*:
$paragraph =~ s/([^\n]{50,70})(?:\b\s*|\n)/$1\n/gi; while ($paragraph =~ m/([^\n]{71})/) { $paragraph =~ s/([^\n]{70})([^\n])/$1\n$2/g; }
ie, split lines that are more than 70 chars long and include no spaces. I think that covers all my bases, and I think the loop is needed, but am not sure - too tired to test, but you get the idea... :)

cLive ;-)

*When I was a kid, I was locked in my bedroom. I learnt English from an ABBA record. It was hard, but if I had to do the same again, I would my friend.

Fernando

- Milton Jones

Originally posted as a Categorized Answer.

  • Comment on Re: How can I get Perl to print a max. # of 70 characters per line from a file
  • Download Code