1Text::Table::Tiny(3) User Contributed Perl Documentation Text::Table::Tiny(3)
2
3
4
6 Text::Table::Tiny - simple text tables from 2D arrays, with limited
7 templating options
8
10 use Text::Table::Tiny 0.04 qw/ generate_table /;
11
12 my $rows = [
13 # header row
14 ['Name', 'Rank', 'Serial'],
15 # rows
16 ['alice', 'pvt', '123456'],
17 ['bob', 'cpl', '98765321'],
18 ['carol', 'brig gen', '8745'],
19 ];
20 print generate_table(rows => $rows, header_row => 1);
21
23 This module provides a single function, "generate_table", which formats
24 a two-dimensional array of data as a text table.
25
26 The example shown in the SYNOPSIS generates the following table:
27
28 +-------+----------+----------+
29 | Name | Rank | Serial |
30 +-------+----------+----------+
31 | alice | pvt | 123456 |
32 | bob | cpl | 98765321 |
33 | carol | brig gen | 8745 |
34 +-------+----------+----------+
35
36 NOTE: the interface changed with version 0.04, so if you use the
37 "generate_table()" function illustrated above, then you need to require
38 at least version 0.04 of this module, as shown in the SYNOPSIS.
39
40 OPTIONS
41 The "generate_table" function understands three arguments, which are
42 passed as a hash.
43
44 · rows
45
46 Takes an array reference which should contain one or more rows of
47 data, where each row is an array reference.
48
49 · header_row
50
51 If given a true value, the first row in the data will be
52 interpreted as a header row, and separated from the rest of the
53 table with a ruled line.
54
55 · separate_rows
56
57 If given a true value, a separator line will be drawn between every
58 row in the table, and a thicker line will be used for the header
59 separator.
60
61 EXAMPLES
62 If you just pass the data and no other options:
63
64 generate_table(rows => $rows);
65
66 You get minimal ruling:
67
68 +-------+----------+----------+
69 | Name | Rank | Serial |
70 | alice | pvt | 123456 |
71 | bob | cpl | 98765321 |
72 | carol | brig gen | 8745 |
73 +-------+----------+----------+
74
75 If you want lines between every row, and also want a separate header:
76
77 generate_table(rows => $rows, header_row => 1, separate_rows => 1);
78
79 You get the maximally ornate:
80
81 +-------+----------+----------+
82 | Name | Rank | Serial |
83 O=======O==========O==========O
84 | alice | pvt | 123456 |
85 +-------+----------+----------+
86 | bob | cpl | 98765321 |
87 +-------+----------+----------+
88 | carol | brig gen | 8745 |
89 +-------+----------+----------+
90
92 You can set a number of package variables inside the
93 "Text::Table::Tiny" package to configure the appearance of the table.
94 This interface is likely to be deprecated in the future, and some other
95 mechanism provided.
96
97 · $Text::Table::Tiny::COLUMN_SEPARATOR = '|';
98
99 · $Text::Table::Tiny::ROW_SEPARATOR = '-';
100
101 · $Text::Table::Tiny::CORNER_MARKER = '+';
102
103 · $Text::Table::Tiny::HEADER_ROW_SEPARATOR = '=';
104
105 · $Text::Table::Tiny::HEADER_CORNER_MARKER = 'O';
106
108 Prior to version 0.04 this module provided a function called "table()",
109 which wasn't available for export. It took exactly the same arguments:
110
111 use Text::Table::Tiny;
112 my $rows = [ ... ];
113 print Text::Table::Tiny::table(rows => $rows, separate_rows => 1, header_row => 1);
114
115 For backwards compatibility this interface is still supported. The
116 "table()" function isn't available for export though.
117
119 There are many modules for formatting text tables on CPAN. A good
120 number of them are listed in the See Also
121 <https://metacpan.org/pod/Text::Table::Manifold#See-Also> section of
122 the documentation for Text::Table::Manifold.
123
125 <https://github.com/neilb/Text-Table-Tiny>
126
128 Creighton Higgins <chiggins@chiggins.com>
129
130 Now maintained by Neil Bowers <neilb@cpan.org>
131
133 This software is copyright (c) 2012 by Creighton Higgins.
134
135 This is free software; you can redistribute it and/or modify it under
136 the same terms as the Perl 5 programming language system itself.
137
138
139
140perl v5.28.0 2015-11-05 Text::Table::Tiny(3)