NAME

Text::Table::Sprintf - Generate simple text tables from 2D arrays using sprintf()

VERSION

This document describes version 0.001 of Text::Table::Sprintf (from Perl distribution Text-Table-Sprintf), released on 2020-08-10.

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);

DESCRIPTION

This module provides a single function, table, which formats a two-dimensional array of data as a simple text table.

The example shown in the SYNOPSIS generates the following table:

 +-------+----------+----------+
 | Name  | Rank     | Serial   |
 +-------+----------+----------+
 | alice | pvt      | 123456   |
 | bob   | cpl      | 98765321 |
 | carol | brig gen | 8745     |
 +-------+----------+----------+

This module models its interface on Text::Table::Tiny 0.03, employs the same technique of using sprintf(), but takes the technique further by using a single large format and sprintf the whole table. This results in even more performance gain (see benchmark result or benchmark using Acme::CPANModules::TextTable).

Caveats: 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).

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)

    Takes an array reference which should contain one or more rows of data, where each row is an array reference.

  • header_row (bool)

    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.

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.

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.

SEE ALSO

Text::Table::Tiny

Other text table modules listed in Acme::CPANModules::TextTable.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by 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.