Bootstrap FreeKB - Perl (Scripting) - Wrap text (Text::Wrap)
Perl (Scripting) - Wrap text (Text::Wrap)

Updated:   |  Perl (Scripting) articles

The Text::Wrap module can be used to wrap text in Perl. In this example, the text will be wrapped at every 20 characters.

use Text::Wrap;
$Text::Wrap::columns = 20;

$example = "A long string of data A long string of data A long string of data A long string of data";

print wrap('', '', $example);

 

Running this script will produce  the following output. Notice that instead of wrapping at 20 characters exactly, whole words are not split.

A long string of 
data A long string 
of data A long 
string of data A 
long string of data

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter b3a723 in the box below so that we can be sure you are a human.