[PerlChina] 写了个模块Pretty::Table,请大家测试

Shan Leiguang shanleiguang at gmail.com
Wed May 7 05:54:58 PDT 2008


写了个模块Pretty::Table,可以打印比较漂亮的格式对齐的文本表格,可用于生成文本报表或日志文件,请大家测试,欢迎反馈你的意见和建议。


=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 at 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 at 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 at gmail.c |        |
  |       |       |       | om         |        |
  *-------*-------*-------*------------*--------*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/china-pm/attachments/20080507/de379e9a/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Pretty-0.2.tar.gz
Type: application/x-gzip
Size: 4489 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/china-pm/attachments/20080507/de379e9a/attachment.gz 


More information about the China-pm mailing list