1lib.modern::Text::Wrap(U3s)er Contributed Perl Documentatliiobn.modern::Text::Wrap(3)
2
3
4

NAME

6       Text::Wrap - line wrapping to form simple paragraphs
7

SYNOPSIS

9       Example 1
10
11               use Text::Wrap;
12
13               $initial_tab = "\t";    # Tab before first line
14               $subsequent_tab = "";   # All other lines flush left
15
16               print wrap($initial_tab, $subsequent_tab, @text);
17               print fill($initial_tab, $subsequent_tab, @text);
18
19               $lines = wrap($initial_tab, $subsequent_tab, @text);
20
21               @paragraphs = fill($initial_tab, $subsequent_tab, @text);
22
23       Example 2
24
25               use Text::Wrap qw(wrap $columns $huge);
26
27               $columns = 132;         # Wrap at 132 characters
28               $huge = 'die';
29               $huge = 'wrap';
30               $huge = 'overflow';
31
32       Example 3
33
34               use Text::Wrap;
35
36               $Text::Wrap::columns = 72;
37               print wrap('', '', @text);
38

DESCRIPTION

40       Text::Wrap::wrap() is a very simple paragraph formatter.  It formats a
41       single paragraph at a time by breaking lines at word boundaries.
42       Indentation is controlled for the first line ($initial_tab) and all
43       subsequent lines ($subsequent_tab) independently.  Please note:
44       $initial_tab and $subsequent_tab are the literal strings that will be
45       used: it is unlikely you would want to pass in a number.
46
47       Text::Wrap::fill() is a simple multi-paragraph formatter.  It formats
48       each paragraph separately and then joins them together when it's done.
49       It will destroy any whitespace in the original text.  It breaks text
50       into paragraphs by looking for whitespace after a newline.  In other
51       respects, it acts like wrap().
52
53       wrap() compresses trailing whitespace into one newline, and fill()
54       deletes all trailing whitespace.
55
56       Both wrap() and fill() return a single string.
57
58       Unlike the old Unix fmt(1) utility, this module correctly accounts for
59       any Unicode combining characters (such as diacriticals) that may occur
60       in each line for both expansion and unexpansion.  These are overstrike
61       characters that do not increment the logical position.  Make sure you
62       have the appropriate Unicode settings enabled.
63

OVERRIDES

65       Text::Wrap::wrap() has a number of variables that control its behavior.
66       Because other modules might be using Text::Wrap::wrap() it is suggested
67       that you leave these variables alone!  If you can't do that, then use
68       "local($Text::Wrap::VARIABLE) = YOURVALUE" when you change the values
69       so that the original value is restored.  This local() trick will not
70       work if you import the variable into your own namespace.
71
72       Lines are wrapped at $Text::Wrap::columns columns (default value: 76).
73       $Text::Wrap::columns should be set to the full width of your output
74       device.  In fact, every resulting line will have length of no more than
75       "$columns - 1".
76
77       It is possible to control which characters terminate words by modifying
78       $Text::Wrap::break. Set this to a string such as '[\s:]' (to break
79       before spaces or colons) or a pre-compiled regexp such as "qr/[\s']/"
80       (to break before spaces or apostrophes). The default is simply '\s';
81       that is, words are terminated by spaces.  (This means, among other
82       things, that trailing punctuation  such as full stops or commas stay
83       with the word they are "attached" to.)  Setting $Text::Wrap::break to a
84       regular expression that doesn't eat any characters (perhaps just a
85       forward look-ahead assertion) will cause warnings.
86
87       Beginner note: In example 2, above $columns is imported into the local
88       namespace, and set locally.  In example 3, $Text::Wrap::columns is set
89       in its own namespace without importing it.
90
91       Text::Wrap::wrap() starts its work by expanding all the tabs in its
92       input into spaces.  The last thing it does it to turn spaces back into
93       tabs.  If you do not want tabs in your results, set
94       $Text::Wrap::unexpand to a false value.  Likewise if you do not want to
95       use 8-character tabstops, set $Text::Wrap::tabstop to the number of
96       characters you do want for your tabstops.
97
98       If you want to separate your lines with something other than "\n" then
99       set $Text::Wrap::separator to your preference.  This replaces all
100       newlines with $Text::Wrap::separator.  If you just want to preserve
101       existing newlines but add new breaks with something else, set
102       $Text::Wrap::separator2 instead.
103
104       When words that are longer than $columns are encountered, they are
105       broken up.  wrap() adds a "\n" at column $columns.  This behavior can
106       be overridden by setting $huge to 'die' or to 'overflow'.  When set to
107       'die', large words will cause die() to be called.  When set to
108       'overflow', large words will be left intact.
109
110       Historical notes: 'die' used to be the default value of $huge.  Now,
111       'wrap' is the default value.
112

EXAMPLES

114       Code:
115
116         print wrap("\t","",<<END);
117         This is a bit of text that forms
118         a normal book-style indented paragraph
119         END
120
121       Result:
122
123         "     This is a bit of text that forms
124         a normal book-style indented paragraph
125         "
126
127       Code:
128
129         $Text::Wrap::columns=20;
130         $Text::Wrap::separator="|";
131         print wrap("","","This is a bit of text that forms a normal book-style paragraph");
132
133       Result:
134
135         "This is a bit of|text that forms a|normal book-style|paragraph"
136

SEE ALSO

138       For correct handling of East Asian half- and full-width characters, see
139       Text::WrapI18N.  For more detailed controls: Text::Format.
140

AUTHOR

142       David Muir Sharnoff <cpan@dave.sharnoff.org> with help from Tim Pierce
143       and many many others.
144

LICENSE

146       Copyright (C) 1996-2009 David Muir Sharnoff.  Copyright (C) 2012-2013
147       Google, Inc.  This module may be modified, used, copied, and
148       redistributed at your own risk.  Although allowed by the preceding
149       license, please do not publicly redistribute modified versions of this
150       code with the name "Text::Wrap" unless it passes the unmodified
151       Text::Wrap test suite.
152
153
154
155perl v5.38.0                      2023-07-21         lib.modern::Text::Wrap(3)
Impressum