Skip to content
Create basic tables from a two dimensional array
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
lib/Text/Table
t
.appveyor.yml
.travis.yml
LICENSE
META6.json
README.pod

README.pod

Text::Table::Simple

Create basic tables from a two dimensional array

Synopsis

use Text::Table::Simple;

my @columns = <id name email>;
my @rows    = (
    [1,"John Doe",'johndoe@cpan.org'],
    [2,'Jane Doe','mrsjanedoe@hushmail.com'],
);

my @table = lol2table(@columns,@rows);
.say for @table;

# O----O----------O-------------------------O
# | id | name     | email                   |
# O====O==========O=========================O
# | 1  | John Doe | johndoe@cpan.org        |
# | 2  | Jane Doe | mrsjanedoe@hushmail.com |
# -------------------------------------------

Exports

routine lol2table

Args @body, *%options

Args @header, @body, @footer?, *%options

Returns Str @rows

Create a an array of strings that can be printed line by line to create a table view of the data.

> my @cols = <XXX XXXX>;
> my @rows = ([1,2],[3,4]);
> say lol2table(@cols, @rows).join("\n");

O-----O------O
| XXX | XXXX |
O=====O======O
| 1   | 2    |
| 3   | 4    |
--------------

Options

# default values
%options = %(
    rows => {
        column_separator     => '|',
        corner_marker        => '-',
        bottom_border        => '-',
    },
    headers => {
        top_border           => '-',
        column_separator     => '|',
        corner_marker        => 'O',
        bottom_border        => '=',
    },
    footers => {
        column_separator     => 'I',
        corner_marker        => '%',
        bottom_border        => '*',
    },
);

You can replace any of the default options above by passing in a replacement

> my @cols = <XXX XXXX>;
> my @rows = ([1,2],[3,4]);
> .say for lol2table(@cols, @rows, rows => column_separator => "?"  );

O-----O------O
| XXX | XXXX |
O=====O======O
? 1   ? 2    ?
? 3   ? 4    ?
--------------

Examples

Showing your Benchmark output:

use Text::Table::Simple;

use Text::Levenshtein::Damerau; 
use Benchmark;

my $str1 = "lsd";
my $str2 = "lds";

my %results = timethese(1000, {
    'dld' => sub { Text::Levenshtein::Damerau::{"&dld($str1,$str2)"} },
    'ld ' => sub { Text::Levenshtein::Damerau::{"&ld($str1,$str2)"}  },
});

my @headers = ['func','start','end','diff','avg'];
my @rows    = %results.map: {.key, .value.Slip}
my @table   = lol2table(@headers,@rows);

.say for @table;

Also see the examples directory

You can’t perform that action at this time.