From: David Muir Sharnoff Date: Wed, 18 Dec 1996 06:59:59 +0000 (-0800) Subject: Please update Text::Wrap and Text::Tabs X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4fc6b8d8b1c6c2152c9aca876e60cc657bf252e6;p=p5sagit%2Fp5-mst-13.2.git Please update Text::Wrap and Text::Tabs In the next perl releae, please include the latest versions of Text::Wrap and Text::Tabs. They always be found in the nearest CPAN. Actually, I'm not sure how far behind (if any) the current source is, but I keep getting bug reports from old versions so I thought I should make sure... p5p-msgid: <199612180659.WAA24957@idiom.com> --- diff --git a/lib/Text/Tabs.pm b/lib/Text/Tabs.pm index 4024d7b..acd7afb 100644 --- a/lib/Text/Tabs.pm +++ b/lib/Text/Tabs.pm @@ -7,7 +7,7 @@ require Exporter; @EXPORT = qw(expand unexpand $tabstop); use vars qw($VERSION $tabstop $debug); -$VERSION = 96.051501; +$VERSION = 96.121201; use strict; @@ -27,7 +27,7 @@ sub expand /sex; } return @l if wantarray; - return @l[0]; + return $l[0]; } sub unexpand @@ -60,7 +60,7 @@ sub unexpand $x = join("\n", @lines); } return @l if wantarray; - return @l[0]; + return $l[0]; } 1; @@ -69,15 +69,15 @@ __END__ =head1 NAME -Text::Tabs - expand and unexpand tabs per the unix expand(1) and unexpand(1) +Text::Tabs -- expand and unexpand tabs per the unix expand(1) and unexpand(1) =head1 SYNOPSIS - use Text::Tabs; +use Text::Tabs; - $tabstop = 4; - @lines_without_tabs = expand(@lines_with_tabs); - @lines_with_tabs = unexpand(@lines_without_tabs); +$tabstop = 4; +@lines_without_tabs = expand(@lines_with_tabs); +@lines_with_tabs = unexpand(@lines_without_tabs); =head1 DESCRIPTION @@ -94,4 +94,4 @@ entire document in one string. Instead feed it an array of lines. =head1 AUTHOR -David Muir Sharnoff EFE +David Muir Sharnoff diff --git a/lib/Text/Wrap.pm b/lib/Text/Wrap.pm index 2ffc69e..96ccf7e 100644 --- a/lib/Text/Wrap.pm +++ b/lib/Text/Wrap.pm @@ -9,6 +9,7 @@ require Exporter; $VERSION = 96.041801; use vars qw($VERSION $columns $debug); +use strict; BEGIN { $columns = 76; # <= screen width @@ -16,7 +17,6 @@ BEGIN { } use Text::Tabs; -use strict; sub wrap { @@ -63,6 +63,7 @@ sub wrap return $r; } + 1; __DATA__ @@ -82,7 +83,7 @@ Text::Wrap - line wrapping to form simple paragraphs =head1 DESCRIPTION -Text::Wrap is a very simple paragraph formatter. It formats a +Text::Wrap::wrap() is a very simple paragraph formatter. It formats a single paragraph at a time by breaking lines at word boundries. Indentation is controlled for the first line ($initial_tab) and all subsquent lines ($subsequent_tab) independently. $Text::Wrap::columns @@ -95,6 +96,38 @@ should be set to the full width of your output device. =head1 AUTHOR -David Muir Sharnoff EFE +David Muir Sharnoff with help from Tim Pierce and +others. =cut + + print fill($initial_tab, $subsequent_tab, @text); + + print fill("", "", `cat book`); + +Text::Wrap::fill() is a simple multi-paragraph formatter. It formats +each paragraph separately and then joins them together when it's done. It +will destory any whitespace in the original text. It breaks text into +paragraphs by looking for whitespace after a newline. In other respects +it acts like wrap(). + +# Tim Pierce did a faster version of this: + +sub fill +{ + my ($ip, $xp, @raw) = @_; + my @para; + my $pp; + + for $pp (split(/\n\s+/, join("\n",@raw))) { + $pp =~ s/\s+/ /g; + my $x = wrap($ip, $xp, $pp); + push(@para, $x); + } + + # if paragraph_indent is the same as line_indent, + # separate paragraphs with blank lines + + return join ($ip eq $xp ? "\n\n" : "\n", @para); +} +