下面是一个断行的示例
+========+=========+===============+=============+=============+| Record | Cluster | Current Build | Current Use | Environment |+--------+---------+---------------+-------------+-------------+| 3 | 1 | v44 | v44 live (currently - new company cluster)| PROD |+--------+---------+---------------+-------------+-------------+
这是我正在使用的(kludgy)代码
sub printData { if (@_) { # print the data grID top border printf ("%10s%10s%15s%14s%14s",'+'.('=' x 8).'+',('=' x 9).'+',('=' x 15).'+',('=' x 13).'+',('=' x 13).'+'); print "\n"; # print the data grID column Titles printf ("%-9s%-10s%-16s%-14s%-15s",'| Record ','| Cluster ','| Current Build ','| Current Use ','| Environment |'); print "\n"; # print out each row of data foreach my $rows (@_) { # print the data grID demarcation border printf ("%10s%10s%15s%14s%14s",'+'.('-' x 8).'+',('-' x 9).'+',('-' x 15).'+',('-' x 13).'+',('-' x 13).'+'); print "\n"; # print each data cell printf ("%-9s",'| '.$rows->{'Record ID#'}); printf ("%-10s",'| '.$rows->{'Cluster'}); printf ("%-16s",'| '.$rows->{'Current Build'}); printf ("%-14s",'| '.$rows->{'Current Use'}); # calculate the length of the last column my $length = length($rows->{'Environment'}); # calculate how many spaces to add to the last column # the Title of this column uses 15 characters (including '|' and spaces) # we already used three of those spaces for 2 '|' characters and 1 leading space # so 15 - 3 = 12 # then subtract the length of the return string from 12 my $spaces = 12 - $length; # we print the last data cell plus the padding spaces calculated above printf ("%-15s",'| '.$rows->{'Environment'}.(' ' x $spaces).'|'); print "\n"; } # we print the bottom data grID border printf ("%10s%10s%15s%14s%14s",('=' x 13).'+'); print "\n"; } else { if ($deBUG) { print "trouble with printData subroutine\n"; } return 0; }}解决方法 Text::Table将调整列宽以适合数据. 总结
以上是内存溢出为你收集整理的数组 – 以可变宽度列打印数组内容全部内容,希望文章能够帮你解决数组 – 以可变宽度列打印数组内容所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)