NAME
Text::PrettyTable - Allow for auto-fixed-width formatting of raw data
DEPENDENCIES
This module doesn't require any dependencies.
SYNOPSIS
perl -MText::PrettyTable -e 'print pretty_table([qw(Hello Hey There)])'
┌───────┐
│ Hello │
│ Hey │
│ There │
└───────┘
perl -MText::PrettyTable -e 'print pretty_table([qw(99 1000 2)])'
┌──────┐
│ 99 │
│ 1000 │
│ 2 │
└──────┘
perl -MText::PrettyTable -e 'print pretty_table([qw(99 1000 2)], {title => ["Stuff"], unibox => 0})'
+-------+
| Stuff |
+-------+
| 99 |
| 1000 |
| 2 |
+-------+
perl -MText::PrettyTable -e 'print pretty_table({id=>23,hi => "HI", cool => 1})'
┌──────┬────┐
│ id │ 23 │
│ cool │ 1 │
│ hi │ HI │
└──────┴────┘
perl -MText::PrettyTable -e 'print pretty_table({id=>23,hi => "HI", cool => 1}, {title => [qw(Key Value)]})'
┌──────┬───────┐
│ Key │ Value │
├──────┼───────┤
│ id │ 23 │
│ cool │ 1 │
│ hi │ HI │
└──────┴───────┘
perl -MText::PrettyTable -e 'print pretty_table([{id=>23,hi => "HI", cool => 1}, {id => 7,hi => "George", cool => "two"}])'
┌────┬──────┬────────┐
│ id │ cool │ hi │
├────┼──────┼────────┤
│ 23 │ 1 │ HI │
│ 7 │ two │ George │
└────┴──────┴────────┘
perl -MText::PrettyTable -e 'print pretty_table({id => 23, hi => "HI", cool => [qw(a cee)]})'
┌──────┬─────────┐
│ id │ 23 │
│ cool │ ┌─────┐ │
│ │ │ a │ │
│ │ │ cee │ │
│ │ └─────┘ │
│ hi │ HI │
└──────┴─────────┘
perl -MText::PrettyTable -e 'print pretty_table([{id => 23, hi => "HI", cool => [qw(a cee)]}])'
┌────┬─────────┬────┐
│ id │ cool │ hi │
├────┼─────────┼────┤
│ 23 │ ┌─────┐ │ HI │
│ │ │ a │ │ │
│ │ │ cee │ │ │
│ │ └─────┘ │ │
└────┴─────────┴────┘
perl -MText::PrettyTable -e 'print pretty_table([{id=>23,hi => "HI", cool => 1}, "Wow", {hi => "Row1\nRow2", cool => 98, id=>""}])'
┌────┬──────┬──────┐
│ id │ cool │ hi │
├────┼──────┼──────┤
│ 23 │ 1 │ HI │
│ Wow │
│ │ 98 │ Row1 │
│ │ │ Row2 │
└────┴──────┴──────┘
perl -MText::PrettyTable -e 'print pretty_table([({one => "A"x50, two => "B"x50})x2])'
┌────────────────────────────────────────────────────┬────────────────────────────────────────────────────┐
│ one │ two │
├────────────────────────────────────────────────────┼────────────────────────────────────────────────────┤
│ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA │ BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB │
│ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA │ BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB │
└────────────────────────────────────────────────────┴────────────────────────────────────────────────────┘
perl -MText::PrettyTable -e 'print pretty_table([({one => "A"x50, two => "B"x50})x2], {auto_collapse => 100})'
┌──────────────────────────────────────────────────────────────┐
│ ┌─────┬────────────────────────────────────────────────────┐ │
│ │ one │ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA │ │
│ │ two │ BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB │ │
│ └─────┴────────────────────────────────────────────────────┘ │
│ ┌─────┬────────────────────────────────────────────────────┐ │
│ │ one │ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA │ │
│ │ two │ BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB │ │
│ └─────┴────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────┘
# auto_collapse => 1 will try and determine columns from the terminal
METHODS
- pretty_table( $data [, $args] )
-
Function. Exported by default. Calls Text::PrettyTable->tablify(@_).
use Text::PrettyTable; print pretty_table([qw(one two three)]); print pretty_table([qw(Alice Bob Chuck)], {title => ["Guest"]}); # Output: ┌───────┐ │ one │ │ two │ │ three │ └───────┘ ┌───────┐ │ Guest │ ├───────┤ │ Alice │ │ Bob │ │ Chuck │ └───────┘
- plain_text( $data [, $args] )
-
Method. Alias for "tablify" only for backwards compatibility.
- tablify( $data [, $args] )
-
Method. Can be called as a static class method or an object method. The first argument $data must be a HASH ref or ARRAY ref. Returns a string of a table represention of the $data structure. Optional $args hash can be used to override previous object settings or to override default settings.
print Text::PrettyTable->tablify($data, {auto_collapse => 100}); # or print Text::PrettyTable->tablify($data, {auto_collapse => 100}); # or my $pt = Text::PrettyTable->new({auto_collapse => 100}); print $pt->tablify($data); # or print $pt->tablify($data, {auto_collapse => 150}); # or
ARGUMENTS
- auto_collapse
-
If set will try and automatically shrink the width based on the terminal width.
- sort
-
A sort order for keys. By default it sorts hashes by key. Any key not in this sort order will not be present in the output.
- split
-
Default is 100. Length at which to split long lines. Can also be set via $Text::PrettyTable::split.
- title
-
By default hashes do not have a title header. You can pass in a two item arrayref to label the columns.
title => [qw(Key Value)],
Arrays of non-hashrefs also do not have a title header. You can pass in a title header for these as well.
title => [qw(My Array Column Headings)],
- unibox
-
Now default true. Enables unicode box borders. Can be either a true value, or can be a 16 element array defining the border box (See the code for a sample of alternate boxes). Can also be set via $Text::PrettyTable::unibox.
SEE ALSO
Similar idea with the following:
Data::Format::Pretty::Console
AUTHOR
Paul Seamons <paul@seamons.org>
Rob Brown <bbb@cpan.org>
COPYRIGHT AND LICENSE
Copyright 2025 by Rob Brown <bbb@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.