Word wrap in perl

Word wrap plays an important role while displaying any output to the standard output or a file. This is used to display the output neatly and in a ordered way.

#!/usr/bin/perl -w
use strict;

 use Text::Wrap;
 undef $/;
 print wrap('', '', split(/\s*\n\s*/, ));
use Text::Wrap qw(&wrap $columns);
use Term::ReadKey qw(GetTerminalSize);
($columns) = GetTerminalSize();
print $columns;
($/, $\) = ('', "\n\n"); # read by paragraph, output 2 newlines
while () { # grab a full paragraph
s/\s*\n\s*/ /g; # convert intervening newlines to spaces
print wrap('', '', $_); # and format
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s