Text::Table::Tiny(3)

πŸ“¦
version 1.03 Β· 2 versions
, in fedora 43

✨ Text::Table::Tiny ✨

okay so bestie, welcome to Text::Table::Tiny β€” she's a Perl module (that's the (3) up in the corner, that's just how us manual pages say hi πŸ’…) and she does exactly one thing but she does it beautifully: she turns a 2D array into a cute lil text table. periodt.


🌸 SYNOPSIS 🌸

use Text::Table::Tiny 1.02 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 πŸ¦‹

So this module gives you exactly one function, generate_table, and what it does is format a two-dimensional array of data as a text table. That's it. That's the whole job. And she eats, no cap.

She also handles text that includes ANSI escape codes and wide Unicode characters, which is the kind of thing that makes other table modules cry in the group chat 😭.

There are a bunch of options for adjusting the output format, but the vibe is that the default option is good enough for most uses. Like, you don't have to customize. She's already cute.

The example in the SYNOPSIS generates this:

+------------+---------+-------+
| Pokemon    | Type    | Count |
+------------+---------+-------+
| Abra       | Psychic | 5     |
| Ekans      | Poison  | 123   |
| Feraligatr | Water   | 5678  |
+------------+---------+-------+
Support for wide characters was added in 1.02, so if you need that, you should specify that as your minimum required version, as per the SYNOPSIS. iykyk.
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.
Some of the options described below were added in version 1.00, so your best bet is to require at least version 1.00. πŸ’–

πŸŽ€ 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.

If you pass an unknown argument, generate_table will die with an error message. like, she will literally end it πŸ’€ so double-check your spelling bestie.

  • rows β€” Takes an array reference which should contain one or more rows of data, where each row is an array reference.
  • 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.
  • header β€” Takes an array reference which has the header row to use for the table. You can't use this option together with header_row. Added in 1.03.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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. (yes, that one, scroll up bestie 🫢)

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. (fr fr, don't skip that part πŸ™ˆ)

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Pokemon    β”‚ Type    β”‚ Count β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Abra       β”‚ Psychic β”‚ 5     β”‚
β”‚ Ekans      β”‚ Poison  β”‚ 123   β”‚
β”‚ Feraligatr β”‚ Water   β”‚ 5678  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜

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:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Pokemon    β”‚ Type    β”‚ Count β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Abra       β”‚ Psychic β”‚     5 β”‚
β”‚ Ekans      β”‚ Poison  β”‚   123 β”‚
β”‚ Feraligatr β”‚ Water   β”‚  5678 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜

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:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”
β”‚Pokemon   β”‚Type   β”‚Countβ”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€
β”‚Abra      β”‚Psychicβ”‚    5β”‚
β”‚Ekans     β”‚Poison β”‚  123β”‚
β”‚Feraligatrβ”‚Water  β”‚ 5678β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”˜

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:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Pokemon    β”‚ Type    β”‚ Count β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•ͺ═════════β•ͺ═══════║
β”‚ Abra       β”‚ Psychic β”‚     5 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Ekans      β”‚ Poison  β”‚   123 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Feraligatr β”‚ Water   β”‚  5678 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜

You can use this with the other styles, but I'm not sure you'd want to. (lowkey a warning, highkey a warning πŸ’€)

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. (iconic behaviour honestly ✨)


πŸ‘‘ SEE ALSO πŸ‘‘


πŸ’œ 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.


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.


and that's the whole page bestie!! this was perl v5.42.0, dated 2025-07-25, and it's the manual page for Text::Table::Tiny(3) β€” go forth and make tables, you absolute main character πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from