7 @EXPORT_OK = qw($columns);
11 use vars qw($VERSION $columns $debug);
15 $columns = 76; # <= screen width
19 use Text::Tabs qw(expand unexpand);
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
46 if ( $t =~ s/^([^\n]{0,$ll})(\s|\Z(?!\n))//xm ) {
47 print "\$2 is '$2'\n" if $debug;
49 $r .= unexpand("\n" . $lead . $1);
50 } elsif ($t =~ s/^([^\n]{$ll})//) {
52 $r .= unexpand("\n" . $lead . $1);
58 die "couldn't wrap '$t'"
61 print "-----------$r---------\n" if $debug;
63 print "Finish up with '$lead', '$t'\n" if $debug;
65 $r .= $lead . $t if $t ne "";
67 print "-----------$r---------\n" if $debug;;
76 Text::Wrap - line wrapping to form simple paragraphs
82 print wrap($initial_tab, $subsequent_tab, @text);
84 use Text::Wrap qw(wrap $columns);
90 Text::Wrap::wrap() is a very simple paragraph formatter. It formats a
91 single paragraph at a time by breaking lines at word boundries.
92 Indentation is controlled for the first line ($initial_tab) and
93 all subsquent lines ($subsequent_tab) independently. $Text::Wrap::columns
94 should be set to the full width of your output device.
98 print wrap("\t","","This is a bit of text that forms
99 a normal book-style paragraph");
103 It's not clear what the correct behavior should be when Wrap() is
104 presented with a word that is longer than a line. The previous
105 behavior was to die. Now the word is split at line-length.
109 David Muir Sharnoff <muir@idiom.com> with help from Tim Pierce and
114 Latest change by Andreas Koenig <k@anna.in-berlin.de> - 1/17/97
116 print fill($initial_tab, $subsequent_tab, @text);
118 print fill("", "", `cat book`);
120 Text::Wrap::fill() is a simple multi-paragraph formatter. It formats
121 each paragraph separately and then joins them together when it's done. It
122 will destory any whitespace in the original text. It breaks text into
123 paragraphs by looking for whitespace after a newline. In other respects
126 # Tim Pierce did a faster version of this:
130 my ($ip, $xp, @raw) = @_;
134 for $pp (split(/\n\s+/, join("\n",@raw))) {
136 my $x = wrap($ip, $xp, $pp);
140 # if paragraph_indent is the same as line_indent,
141 # separate paragraphs with blank lines
143 return join ($ip eq $xp ? "\n\n" : "\n", @para);