7 @EXPORT_OK = qw($columns);
11 use vars qw($VERSION $columns $debug);
15 $columns = 76; # <= screen width
24 my ($ip, $xp, @t) = @_;
27 my $t = expand(join(" ",@t));
29 my $ll = $columns - length(expand($lead)) - 1;
32 # remove up to a line length of things that aren't
35 if ($t =~ s/^([^\n]{0,$ll})(\s|\Z(?!\n))//xm) {
38 $r .= unexpand($lead . $1);
40 # recompute the leader
42 $ll = $columns - length(expand($lead)) - 1;
45 # repeat the above until there's none left
46 while ($t and $t =~ s/^([^\n]{0,$ll})(\s|\Z(?!\n))//xm) {
47 print "\$2 is '$2'\n" if $debug;
49 $r .= unexpand("\n" . $lead . $1);
54 die "couldn't wrap '$t'"
57 print "-----------$r---------\n" if $debug;
59 print "Finish up with '$lead', '$t'\n" if $debug;
61 $r .= $lead . $t if $t ne "";
63 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 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>