7 @EXPORT_OK = qw($columns $wraplong);
11 use vars qw($VERSION $columns $debug $break $huge);
15 $columns = 76; # <= screen width
18 $huge = 'wrap'; # alternatively: 'die'
21 use Text::Tabs qw(expand unexpand);
25 my ($ip, $xp, @t) = @_;
28 my $t = expand(join(" ",@t));
30 my $ll = $columns - length(expand($ip)) - 1;
31 my $nll = $columns - length(expand($xp)) - 1;
35 while ($t !~ /^\s*$/) {
36 if ($t =~ s/^([^\n]{0,$ll})($break|\Z(?!\n))//xm) {
37 $r .= unexpand($nl . $lead . $1);
39 } elsif ($huge eq 'wrap' && $t =~ s/^([^\n]{$ll})//) {
40 $r .= unexpand($nl . $lead . $1);
42 } elsif ($huge eq 'die') {
43 die "couldn't wrap '$t'";
45 die "This shouldn't happen";
54 print "-----------$r---------\n" if $debug;
56 print "Finish up with '$lead', '$t'\n" if $debug;
58 $r .= $lead . $t if $t ne "";
60 print "-----------$r---------\n" if $debug;;
69 Text::Wrap - line wrapping to form simple paragraphs
75 print wrap($initial_tab, $subsequent_tab, @text);
77 use Text::Wrap qw(wrap $columns $huge);
85 Text::Wrap::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.
90 Lines are wrapped at $Text::Wrap::columns columns.
91 $Text::Wrap::columns should be set to the full width of your output device.
93 When words that are longer than $columns are encountered, they
94 are broken up. Previous versions of wrap() die()ed instead.
95 To restore the old (dying) behavior, set $Text::Wrap::huge to
100 print wrap("\t","","This is a bit of text that forms
101 a normal book-style paragraph");
105 David Muir Sharnoff <muir@idiom.com> with help from Tim Pierce and