Pretty::Table v0.2

Homepage

Desc: Pretty::Table模块,打印格式对齐的文本表格,可用于生成文本表格或格式化日志。

Download: Pretty-0.2.tar.gz

=head1 Example

    use Pretty::Table;

    my $pt = Pretty::Table->new(
        data_type      => 'row',     #row mode
        data_format    => 'ucfirst', #uppercase the first char
        if_multi_lines => 1,         #enable multi-lines mode
        max_col_length => 10,        #set max_col_length to 10
    );

    my $dr = [
        ['id','name','sex','age','email'], #this is a row
        ['01','tommy','male',27],
        ['02','jarry','male',26],
        ['03','shanleiguang',26,'shanleiguang@gmail.com'],
    ];

    $pt->set_data_ref($dr);
    $pt->set_title('Contacts');
    $pt->set_align('left');
    $pt->set_data_format('normal');
    $pt->insert(['04','marry','female',26], 4);
    $pt->sort_by('name');
    print $pt->output();

    $pt->set_data_type('col'); #change to 'col' mode
    $pt->set_deco_cross('*');
    $pt->set_if_has_title(0);
    print $pt->output();

=head1 Example Output

  +---------------------------------------------+
  | Contacts                                    |
  +----+------------+--------+-----+------------+
  | id | name       | sex    | age | email      |
  +----+------------+--------+-----+------------+
  | 01 | tommy      | male   | 27  |            |
  +----+------------+--------+-----+------------+
  | 02 | jarry      | male   | 26  |            |
  +----+------------+--------+-----+------------+
  | 03 | shanleigua | male   | 26  | shanleigua |
  |    | ng         |        |     |
ng@gmail.c |
  |    |            |        |     | om         |
  +----+------------+--------+-----+------------+
  | 04 | marry      | female | 26  |            |
  +----+------------+--------+-----+------------+

  *-------*-------*-------*------------*--------*
  | id    | 01    | 02    | 03         | 04     |
  *-------*-------*-------*------------*--------*
  | name  | tommy | jarry | shanleigua | marry  |
  |       |       |       | ng         |        |
  *-------*-------*-------*------------*--------*
  | sex   | male  | male  | male       | female |
  *-------*-------*-------*------------*--------*
  | age   | 27    | 26    | 26         | 26     |
  *-------*-------*-------*------------*--------*
  | email |       |       | shanleigua |        |
  |       |       |       |
ng@gmail.c |        |
  |       |       |       | om         |        |
  *-------*-------*-------*------------*--------*