<p><font face="courier new,monospace" size="2">写了个模块Pretty::Table,可以打印比较漂亮的格式对齐的文本表格,可用于生成文本报表或日志文件,请大家测试,欢迎反馈你的意见和建议。<br></font></p><p><font face="courier new,monospace" size="2"><br>=head1 Example</font></p>
<p><font face="courier new,monospace" size="2"> use Pretty::Table;</font></p>
<p><font face="courier new,monospace" size="2"> my $pt = Pretty::Table->new(<br> data_type => 'row', #row mode<br> data_format => 'ucfirst', #uppercase the first char<br>
if_multi_lines => 1, #enable multi-lines mode<br> max_col_length => 10, #set max_col_length to 10<br> );</font></p>
<p><font face="courier new,monospace" size="2"> my $dr = [<br> ['id','name','sex','age','email'], #this is a row<br> ['01','tommy','male',27],<br>
['02','jarry','male',26],<br> ['03','shanleiguang',26,'shanleiguang@gmail.com'],<br> ];</font></p>
<p><font face="courier new,monospace" size="2"> $pt->set_data_ref($dr);<br> $pt->set_title('Contacts');<br> $pt->set_align('left');<br> $pt->set_data_format('normal');<br> $pt->insert(['04','marry','female',26], 4);<br>
$pt->sort_by('name');<br> print $pt->output();</font></p>
<p><font face="courier new,monospace" size="2"> $pt->set_data_type('col'); #change to 'col' mode<br> $pt->set_deco_cross('*');<br> $pt->set_if_has_title(0);<br> print $pt->output();</font></p>
<p><font face="courier new,monospace" size="2">=head1 Example Output</font></p>
<p><font size="2"><font face="courier new,monospace"> +---------------------------------------------+<br> | Contacts |<br> +----+------------+--------+-----+------------+<br> | id | name | sex | age | email |<br>
+----+------------+--------+-----+------------+<br> | 01 | tommy | male | 27 | |<br> +----+------------+--------+-----+------------+<br> | 02 | jarry | male | 26 | |<br> +----+------------+--------+-----+------------+<br>
| 03 | shanleigua | male | 26 | shanleigua |<br> | | ng | | | </font><a href="mailto:ng@gmail.c"><font face="courier new,monospace">ng@gmail.c</font></a><font face="courier new,monospace"> |<br>
| | | | | om |<br> +----+------------+--------+-----+------------+<br> | 04 | marry | female | 26 | |<br> +----+------------+--------+-----+------------+</font></font></p>
<p><font size="2"><font face="Trebuchet MS"><font face="courier new,monospace"> *-------*-------*-------*------------*--------*<br> | id | 01 | 02 | 03 | 04 |<br> *-------*-------*-------*------------*--------*<br>
| name | tommy | jarry | shanleigua | marry |<br> | | | | ng | |<br> *-------*-------*-------*------------*--------*<br> | sex | male | male | male | female |<br> *-------*-------*-------*------------*--------*<br>
| age | 27 | 26 | 26 | 26 |<br> *-------*-------*-------*------------*--------*<br> | email | | | shanleigua | |<br> | | | | </font><a href="mailto:ng@gmail.c"><font face="courier new,monospace">ng@gmail.c</font></a><font face="courier new,monospace"> | |<br>
| | | | om | |<br> *-------*-------*-------*------------*--------*</font></font></font></p>