7 @EXPORT_OK = qw($columns);
11 use vars qw($VERSION $columns $debug);
15 $columns = 76; # <= screen width
23 my ($ip, $xp, @t) = @_;
26 my $t = expand(join(" ",@t));
28 my $ll = $columns - length(expand($lead)) - 1;
31 # remove up to a line length of things that aren't
34 if ($t =~ s/^([^\n]{0,$ll})(\s|\Z(?!\n))//xm) {
37 $r .= unexpand($lead . $1);
39 # recompute the leader
41 $ll = $columns - length(expand($lead)) - 1;
44 # repeat the above until there's none left
45 while ($t and $t =~ s/^([^\n]{0,$ll})(\s|\Z(?!\n))//xm) {
46 print "\$2 is '$2'\n" if $debug;
48 $r .= unexpand("\n" . $lead . $1);
53 die "couldn't wrap '$t'"
56 print "-----------$r---------\n" if $debug;
58 print "Finish up with '$lead', '$t'\n" if $debug;
60 $r .= $lead . $t if $t ne "";
62 print "-----------$r---------\n" if $debug;;
72 Text::Wrap - line wrapping to form simple paragraphs
78 print wrap($initial_tab, $subsequent_tab, @text);
80 use Text::Wrap qw(wrap $columns);
86 Text::Wrap::wrap() is a very simple paragraph formatter. It formats a
87 single paragraph at a time by breaking lines at word boundries.
88 Indentation is controlled for the first line ($initial_tab) and
89 all subsquent lines ($subsequent_tab) independently. $Text::Wrap::columns
90 should be set to the full width of your output device.
94 print wrap("\t","","This is a bit of text that forms
95 a normal book-style paragraph");
99 David Muir Sharnoff <muir@idiom.com> with help from Tim Pierce and
104 print fill($initial_tab, $subsequent_tab, @text);
106 print fill("", "", `cat book`);
108 Text::Wrap::fill() is a simple multi-paragraph formatter. It formats
109 each paragraph separately and then joins them together when it's done. It
110 will destory any whitespace in the original text. It breaks text into
111 paragraphs by looking for whitespace after a newline. In other respects
114 # Tim Pierce did a faster version of this:
118 my ($ip, $xp, @raw) = @_;
122 for $pp (split(/\n\s+/, join("\n",@raw))) {
124 my $x = wrap($ip, $xp, $pp);
128 # if paragraph_indent is the same as line_indent,
129 # separate paragraphs with blank lines
131 return join ($ip eq $xp ? "\n\n" : "\n", @para);