5 # This is a very simple paragraph formatter. It formats one
6 # paragraph at a time by wrapping and indenting text.
12 # print wrap($initial_tab,$subsequent_tab,@text);
14 # You can also set the number of columns to wrap before:
16 # $Text::Wrap::columns = 135; # <= width of screen
18 # use Text::Wrap qw(wrap $columns);
22 # The first line will be printed with $initial_tab prepended. All
23 # following lines will have $subsequent_tab prepended.
27 # print wrap("\t","","This is a bit of text that ...");
29 # David Muir Sharnoff <muir@idiom.com>
35 Text::Wrap -- wrap text into a paragraph
41 $Text::Wrap::columns = 20; # Default
42 print wrap("\t","",Hello, world, it's a nice day, isn't it?");
46 This module is a simple paragraph formatter that wraps text into a paragraph
47 and indents each line. The single exported function, wrap(), takes three
48 arguments. The first is included before the first output line, and the
49 second argument is included before each subsequest output line. The third
50 argument is the text to be wrapped.
54 David Muir Sharnoff <muir@idiom.com>
62 @EXPORT_OK = qw($columns);
65 $Text::Wrap::columns = 76; # <= screen width
73 my ($ip, $xp, @t) = @_;
76 my $t = expand(join(" ",@t));
78 my $ll = $Text::Wrap::columns - length(expand($lead)) - 1;
79 if ($t =~ s/^([^\n]{0,$ll})\s//) {
80 $r .= unexpand($lead . $1 . "\n");
82 my $ll = $Text::Wrap::columns - length(expand($lead)) - 1;
83 while ($t =~ s/^([^\n]{0,$ll})\s//) {
84 $r .= unexpand($lead . $1 . "\n");
87 die "couldn't wrap '$t'"