FreeBSD Manual Pages
Text::Table::Tiny(3) User Contributed Perl Documentation Text::Table::Tiny(3) NAME Text::Table::Tiny - generate simple text tables from 2D arrays SYNOPSIS use Text::Table::Tiny 1.00 qw/ generate_table /; my $rows = [ [qw/ Pokemon Type Count /], [qw/ Abra Psychic 5 /], [qw/ Ekans Poison 123 /], [qw/ Feraligatr Water 5678 /], ]; print generate_table(rows => $rows, header_row => 1), "\n"; DESCRIPTION This module provides a single function, "generate_table", which formats a two-dimensional array of data as a text table. There are a number of options for adjusting the output format, but the intention is that the default option is good enough for most uses. The example shown in the SYNOPSIS generates the following table: +------------+---------+-------+ | Pokemon | Type | Count | +------------+---------+-------+ | Abra | Psychic | 5 | | Ekans | Poison | 123 | | Feraligatr | Water | 5678 | +------------+---------+-------+ NOTE: the interface changed with version 0.04, so if you use the "generate_table()" function illustrated above, then you need to require at least version 0.04 of this module, as shown in the SYNOPSIS. NOTE 2: some of the options described below were added in version 1.00, so your best bet is to require version 1.00, as per the SYNOPSIS. generate_table() The "generate_table" function understands a number of arguments, which are passed as a hash. The only required argument is rows. Where arguments were not supported in the original release, the first supporting version is noted. o rows Takes an array reference which should contain one or more rows of data, where each row is an array reference. o header_row If given a true value, the first row in the data will be interpreted as a header row, and separated from the rest of the table with a ruled line. o separate_rows If given a true value, a separator line will be drawn between every row in the table, and a thicker line will be used for the header separator. o top_and_tail If given a true value, then the top and bottom border lines will be skipped. This reduces the vertical height of the generated table. Added in 0.04. o align This takes an array ref with one entry per column, to specify the alignment of that column. Legal values are 'l', 'c', and 'r'. You can also specify a single alignment for all columns. ANSI escape codes are handled. Added in 1.00. o style Specifies the format of the output table. The default is 'classic', but other options are 'boxrule' and 'norule'. If you use the "boxrule" style, you'll probably need to run "binmode(STDOUT, ':utf8')". Added in 1.00. o indent Specify an indent that should be prefixed to every line of the generated table. This can either be a string of spaces, or an integer giving the number of spaces wanted. Added in 1.00. o compact If set to a true value then we omit the single space padding on either side of every column. Added in 1.00. EXAMPLES If you just pass the data and no other options: generate_table(rows => $rows); You get minimal ruling: +------------+---------+-------+ | Pokemon | Type | Count | | Abra | Psychic | 5 | | Ekans | Poison | 123 | | Feraligatr | Water | 5678 | +------------+---------+-------+ If you want a separate header, set the header_row option to a true value, as shown in the SYNOPSIS. To take up fewer lines, you can miss out the top and bottom rules, by setting "top_and_tail" to a true value: generate_table(rows => $rows, header_row => 1, top_and_tail => 1); This will generate the following: | Pokemon | Type | Count | +------------+---------+-------+ | Abra | Psychic | 5 | | Ekans | Poison | 123 | | Feraligatr | Water | 5678 | If you want a more stylish looking table, set the "style" parameter to 'boxrule': binmode(STDOUT,':utf8'); generate_table(rows => $rows, header_row => 1, style => 'boxrule'); This uses the ANSI box rule characters. Note that you will need to ensure UTF output. aaaaaaaaaaaaaa~aaaaaaaaaa~aaaaaaaa a Pokemon a Type a Count a aaaaaaaaaaaaaa1/4aaaaaaaaaa1/4aaaaaaaax a Abra a Psychic a 5 a a Ekans a Poison a 123 a a Feraligatr a Water a 5678 a aaaaaaaaaaaaaa'aaaaaaaaaa'aaaaaaaa You might want to right-align numeric values: generate_table( ... , align => [qw/ l l r /] ); The "align" parameter can either take an arrayref, or a string with an alignment to apply to all columns: aaaaaaaaaaaaaa~aaaaaaaaaa~aaaaaaaa a Pokemon a Type a Count a aaaaaaaaaaaaaa1/4aaaaaaaaaa1/4aaaaaaaax a Abra a Psychic a 5 a a Ekans a Poison a 123 a a Feraligatr a Water a 5678 a aaaaaaaaaaaaaa'aaaaaaaaaa'aaaaaaaa If you're using the boxrule style, you might feel you can remove the padding on either side of every column, done by setting "compact" to a true value: aaaaaaaaaaaa~aaaaaaaa~aaaaaa aPokemon aType aCounta aaaaaaaaaaaa1/4aaaaaaaa1/4aaaaaax aAbra aPsychica 5a aEkans aPoison a 123a aFeraligatraWater a 5678a aaaaaaaaaaaa'aaaaaaaa'aaaaaa You can also ask for a rule between each row, in which case the header rule becomes stronger. This works best when combined with the boxrule style: generate_table( ... , separate_rows => 1 ); Which results in the following: aaaaaaaaaaaaaa~aaaaaaaaaa~aaaaaaaa a Pokemon a Type a Count a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa! a Abra a Psychic a 5 a aaaaaaaaaaaaaa1/4aaaaaaaaaa1/4aaaaaaaax a Ekans a Poison a 123 a aaaaaaaaaaaaaa1/4aaaaaaaaaa1/4aaaaaaaax a Feraligatr a Water a 5678 a aaaaaaaaaaaaaa'aaaaaaaaaa'aaaaaaaa You can use this with the other styles, but I'm not sure you'd want to. If you just want columnar output, use the "norule" style: generate_table( ... , style => 'norule' ); which results in: Pokemon Type Count Abra Psychic 5 Ekans Poison 123 Feraligatr Water 5678 Note that everywhere you saw a line on the previous tables, there will be a space character in this version. So you may want to combine the "top_and_tail" option, to suppress the extra blank lines before and after the body of the table. SEE ALSO My blog post <http://neilb.org/2019/08/06/text-table-tiny-changes.html> where I described changes to formatting; this has more examples. There are many modules for formatting text tables on CPAN. A good number of them are listed in the See Also <https://metacpan.org/pod/Text::Table::Manifold#See-Also> section of the documentation for Text::Table::Manifold. REPOSITORY <https://github.com/neilb/Text-Table-Tiny> AUTHOR Neil Bowers <neilb@cpan.org> The original version was written by Creighton Higgins <chiggins@chiggins.com>, but the module was entirely rewritten for 0.05_01. COPYRIGHT AND LICENSE This software is copyright (c) 2020 by Neil Bowers. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.32.0 2020-08-07 Text::Table::Tiny(3)
NAME | SYNOPSIS | DESCRIPTION | SEE ALSO | REPOSITORY | AUTHOR | COPYRIGHT AND LICENSE
Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=Text::Table::Tiny&sektion=3&manpath=FreeBSD+12.2-RELEASE+and+Ports>