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

zhang ayla aylazh at gmail.com
Fri May 9 07:13:50 PDT 2008


学习!

在08-5-7,Shan Leiguang <shanleiguang at gmail.com> 写道:
>
> 写了个模块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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/china-pm/attachments/20080509/70116b23/attachment.html 


More information about the China-pm mailing list