Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I re-wrap a paragraph to a certain line length?

Tags:

regex

split

perl

I have a big paragraph which I need to split into lines such that each line must not have more than 100 characters and no words must be broken. How would I go about doing this? I guess with regular expressions is the best way but I'm not sure how.

like image 505
Ali G Avatar asked Feb 21 '10 12:02

Ali G


1 Answers

Use Text::Wrap.

Text::Wrap::wrap() is a very simple paragraph formatter. It formats a single paragraph at a time by breaking lines at word boundaries. Indentation is controlled for the first line ($initial_tab) and all subsequent lines ($subsequent_tab) independently.

like image 169
kennytm Avatar answered Sep 27 '22 23:09

kennytm