Text::T...Sprintf(3)
β¨ Text::Table::Sprintf β¨
ok so this is a page from the User Contributed Perl Documentation, section 3 β and bestie, it's a good one. Let's get into it π
π·οΈ NAME
Text::Table::Sprintf β generate simple text tables from 2D arrays using sprintf(). that's it, that's the whole job, and it does it fast πββοΈπ¨
π VERSION
This doc describes version 0.008 of Text::Table::Sprintf (from the Perl distribution Text-Table-Sprintf), released on 2023-11-11. vintage but iconic π
πΈ SYNOPSIS
use Text::Table::Sprintf;
my $rows = [
# header row
['Name', 'Rank', 'Serial'],
# rows
['alice', 'pvt', '123456'],
['bob', 'cpl', '98765321'],
['carol', 'brig gen', '8745'],
];
print Text::Table::Sprintf::table(rows => $rows, header_row => 1);
that's literally the whole vibe. two lines of setup and you're printing tables π«Ά
π¦ DESCRIPTION
This module gives you exactly one function, "table", and what it does is take a two-dimensional array of data and format it as a simple text table. no cap, that's it.
The example from the SYNOPSIS spits out this absolute beauty:
+-------+----------+----------+
| Name | Rank | Serial |
+-------+----------+----------+
| alice | pvt | 123456 |
| bob | cpl | 98765321 |
| carol | brig gen | 8745 |
+-------+----------+----------+
look at those aligned pipes. immaculate. π
This module models its interface on Text::Table::Tiny 0.03, and it employs the same technique of using sprintf() β but it takes that technique further by using a single large format and "sprintf"-ing the whole table in one go. the result? even more performance gain (see the benchmark result, or the benchmark using Acme::CPANModules::TextTable). it's giving speed. π₯
Caveats, and I need you to hear me on this one: make sure each row contains the same number of elements. otherwise the table will not be correctly formatted (cells might move to another row/column). fr fr, don't do this to yourself π
π§ DECLARED FEATURES
Features declared by this module:
π From feature set TextTable
Features from the feature set TextTable declared by this module:
can_align_cell_containing_color_codeValue:no.can_align_cell_containing_newlineValue:no.can_align_cell_containing_wide_characterValue:no.can_colorβ can produce colored table. Value:no.can_color_themeβ allow choosing colors from a named set of palettes. Value:no.can_colspanValue:no.can_customize_borderβ let user customize border character in some way, e.g. selecting from several available borders, disable border. Value:no.can_halignβ provide a way for user to specify horizontal alignment (left/middle/right) of cells. Value:yes. Only supportl(left) andr(right) alignment, notc(center). πcan_halign_individual_cellβ provide a way for user to specify different horizontal alignment (left/middle/right) for individual cells. Value:no.can_halign_individual_columnβ provide a way for user to specify different horizontal alignment (left/middle/right) for individual columns. Value:no.can_halign_individual_rowβ provide a way for user to specify different horizontal alignment (left/middle/right) for individual rows. Value:no.can_hpadβ provide a way for user to specify horizontal padding of cells. Value:no.can_hpad_individual_cellβ provide a way for user to specify different horizontal padding of individual cells. Value:no.can_hpad_individual_columnβ provide a way for user to specify different horizontal padding of individual columns. Value:no.can_hpad_individual_rowβ provide a way for user to specify different horizontal padding of individual rows. Value:no.can_rowspanValue:no.can_set_cell_heightβ allow setting height of rows. Value:no.can_set_cell_height_of_individual_rowβ allow setting height of individual rows. Value:no.can_set_cell_widthβ allow setting height of rows. Value:no.can_set_cell_width_of_individual_columnβ allow setting height of individual rows. Value:no.can_use_box_characterβ can use terminal box-drawing character when drawing border. Value:no.can_valignβ provide a way for user to specify vertical alignment (top/middle/bottom) of cells. Value:no.can_valign_individual_cellβ provide a way for user to specify different vertical alignment (top/middle/bottom) for individual cells. Value:no.can_valign_individual_columnβ provide a way for user to specify different vertical alignment (top/middle/bottom) for individual columns. Value:no.can_valign_individual_rowβ provide a way for user to specify different vertical alignment (top/middle/bottom) for individual rows. Value:no.can_vpadβ provide a way for user to specify vertical padding of cells. Value:no.can_vpad_individual_cellβ provide a way for user to specify different vertical padding of individual cells. Value:no.can_vpad_individual_columnβ provide a way for user to specify different vertical padding of individual columns. Value:no.can_vpad_individual_rowβ provide a way for user to specify different vertical padding of individual rows. Value:no.speedβ subjective speed rating, relative to other text table modules. Value:"fast". β‘
For more details on module features, see Module::Features.
β FUNCTIONS
π table
Usage:
my $table_str = Text::Table::Sprintf::table(%params);
The "table" function understands these arguments, which are passed as a hash. π
rowsβ AoAos. Required. Takes an array reference which should contain one or more rows of data, where each row is an array reference.header_rowβ Bool. Optional. Defaults to false. 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. slay β¨separate_rowsβ Bool. Optional. Defaults to false. If set to true, will draw separator line between data rows.alignβ Str or array of str. Optional. Declare alignment for all columns or for individul columns (yes that's how it's spelled in the original, keeping it π). Valid alignment value is'l'(for left) or'r'(for right), center alignment is currently not supported. Default alignment is left.
π generate_table
Alias for "table", for compatibility with Text::Table::Tiny. same energy, different name π«Ά
π HOMEPAGE
Please visit the project's homepage at <https://metacpan.org/release/Text-Table-Sprintf>.
π¦ SOURCE
Source repository is at <https://github.com/perlancar/perl-Text-Table-Sprintf>.
π SEE ALSO
Text::Table::Tiny- Other text table modules listed in
Acme::CPANModules::TextTable. The selling point ofText::Table::Sprintfis performance and light footprint (just about two pages of code that does not use any module, core or otherwise). two pages!! icon behavior π
π AUTHOR
perlancar <perlancar@cpan.org>
π§ CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me. we love a maintainer who says that π
π COPYRIGHT AND LICENSE
This software is copyright (c) 2023, 2022, 2021, 2020 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
π BUGS
Please report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=Text-Table-Sprintf>.
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. help them help you π«Ά
and that's the whole page, bestie π sign-off time: this rendered under perl v5.42.2, dated 2026-02-15, and it's the Text::Table::Sprintf(3) page from the User Contributed Perl Documentation. no cap, go make some tables β¨ππ
π¦ where this page comes from
- alpine 3.24: perl-text-table-sprintf-doc 0.008-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms