7 @EXPORT_OK = qw($columns);
11 use vars qw($VERSION $columns $debug);
14 $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;;
71 Text::Wrap - line wrapping to form simple paragraphs
77 print wrap($initial_tab, $subsequent_tab, @text);
79 use Text::Wrap qw(wrap $columns);
85 Text::Wrap is a very simple paragraph formatter. It formats a
86 single paragraph at a time by breaking lines at word boundries.
87 Indentation is controlled for the first line ($initial_tab) and
88 all subsquent lines ($subsequent_tab) independently. $Text::Wrap::columns
89 should be set to the full width of your output device.
93 print wrap("\t","","This is a bit of text that forms
94 a normal book-style paragraph");
98 David Muir Sharnoff E<lt>F<muir@idiom.com>E<gt>