Test2:...:Table(3perl)
π Test2::Util::Table β the Test2:...:Table(3perl) page, but make it cute π
okay bestie, welcome to Test2::Util::Table, living its best life in the Perl Programmers Reference Guide πΈ
β¨ NAME β¨
Test2::Util::Table β literally just format a header and some rows into a table, no cap π
π¦ DESCRIPTION π¦
So here's the vibe: some of your failing tests wanna spill the tea about what went wrong, and they do that with diagnostics. This module is the one that takes your messy lil' rows of data and generic-formats them into actual tables, so everything looks cute and readable instead of a wall of chaos. it's giving organized. it's giving iconic. π
π SYNOPSIS π
use Test2::Util::Table qw/table/;
my @table = table(
max_width => 80,
collapse => 1, # Do not show empty columns
header => [ 'name', 'age', 'hair color' ],
rows => [
[ 'Fred Flinstone', 2000000, 'black' ],
[ 'Wilma Flinstone', 1999995, 'red' ],
...,
],
);
# The @table array contains each line of the table, no newlines added.
say $_ for @table;
and this prints a table like this, periodt:
+-----------------+---------+------------+
| name | age | hair color |
+-----------------+---------+------------+
| Fred Flinstone | 2000000 | black |
| Wilma Flinstone | 1999995 | red |
| ... | ... | ... |
+-----------------+---------+------------+
not me getting emotional over alignment. πβ¨
π EXPORTS π
@rows = table(...)
The function returns a list of lines, and bestie listen β those lines do not have the newline "\n" character appended. you add it yourself. that's the deal. π«Ά
Options:
header => [ ... ]β if you want a header, specify it right here. This takes an arrayref with each column's heading. slay.rows => [ [...], [...], ... ]β this should be an arrayref containing an arrayref per row. one arrayref, each row, yep.collapse => $boolβ use this if you want to hide empty columns, meaning any column that has no data in any row. Having a header for the column will not effect collapse. (note: it does not care about your header at all, it only looks at the data, iykyk.)max_width => $numβ set the maximum width of the table. the table may not be this big, but it will be no bigger. If none is specified it will attempt to find the width of your terminal and use that, otherwise it falls back to80.sanitize => $boolβ this will sanitize all the data in the table such that newlines, control characters, and all whitespace except for ASCII 20' 'are replaced with escape sequences. This prevents newlines, tabs, and similar whitespace from disrupting the table. protecting the table's peace fr fr π‘οΈ
Note: newlines are marked as '\n', but a newline is also inserted into the data so that it typically displays in a way that is useful to humans.
Example:
my $field = "foo\nbar\nbaz\n";
print join "\n" => table(
sanitize => 1,
rows => [
[$field, 'col2' ],
['row2 col1', 'row2 col2']
]
);
Prints:
+-----------------+-----------+
| foo\n | col2 |
| bar\n | |
| baz\n | |
| | |
| row2 col1 | row2 col2 |
+-----------------+-----------+
So it marks the newlines by inserting the escape sequence, but it also shows the data across as many lines as it would normally display. both things. at once. main character behavior honestly. π
mark_tail => $boolβ this will replace the last whitespace character of any trailing whitespace with its escape sequence. This makes it easier to notice trailing whitespace when comparing values. no more sneaky invisible spaces gaslighting you π
my $cols = term_size()
Attempts to find the width in columns (characters) of the current terminal. Returns 80 as a safe bet if it cannot find it another way. she's doing her best, and honestly? 80 never misses. π§
πΈ NOTE ON UNICODE/WIDE CHARACTERS πΈ
Some unicode characters, such as "ε©§" ("U+5A67") are wider than others. These will render just fine if you use utf8; as necessary, and Unicode::GCString is installed, however if the module is not installed there will be anomalies in the table:
+-----+-----+---+
| a | b | c |
+-----+-----+---+
| ε©§ | x | y |
| x | y | z |
| x | ε©§ | z |
+-----+-----+---+
bestie this is the table falling apart aesthetically and it will NOT apologize. install Unicode::GCString if you care about wide chars lining up. π
π₯ SOURCE π₯
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. go give it a star, it's free and it's iconic β
π MAINTAINERS π
Chad Granum <exodist@cpan.org>
β AUTHORS β
Chad Granum <exodist@cpan.org>
π COPYRIGHT π
Copyright Chad Granum <exodist@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
and that's the whole page babes π«Ά this was Test2:...:Table(3perl) from perl v5.44.0, dated 2026-10-17 β go format a table, you absolute legend πβ¨
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms