Text::T...Sprintf(3)

πŸ“¦ version 0.008, in alpine 3.24

✨ 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_code Value: no.
  • can_align_cell_containing_newline Value: no.
  • can_align_cell_containing_wide_character Value: no.
  • can_color β€” can produce colored table. Value: no.
  • can_color_theme β€” allow choosing colors from a named set of palettes. Value: no.
  • can_colspan Value: 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 support l (left) and r (right) alignment, not c (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_rowspan Value: 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 of Text::Table::Sprintf is 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 πŸ’…

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