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

joe jiang lamp.purl at gmail.com
Wed May 7 07:04:58 PDT 2008


很酷的纵向列表哦 :D

On 三, 2008-05-07 at 20:54 +0800, Shan Leiguang wrote:
> 写了个模块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         |        |
>   *-------*-------*-------*------------*--------*
> 
> _______________________________________________
> China-pm mailing list
> China-pm at pm.org
> http://mail.pm.org/mailman/listinfo/china-pm



More information about the China-pm mailing list