我有一个像这样的数组
@array = (
1,
some 9-digit number-1,
some 9-digit number-2,
2,
some 9-digit number-3,
some 9-digit number-4
.....and so on
);
现在我想在表格中将其打印为
1 some 9-digit number-1 some 9-digit number-2
2 some 9-digit number-3 some 9-digit number-4
3 some 9-digit number-5 some 9-digit number-6
我还想将表打印到文本文件中。什么逻辑是最好的?
由于
答案 0 :(得分:2)
我明白了。我使用Text::Table
谢谢 - John F
use Text::Table;
my $tb = Text::Table->new( "Heading 1", "Heading 2" , "Heading 3");
for (my $i = 0; $i <= $#array; $i += 3) {
$tb->load([@array[$i, $i+1, $i+2]]);
}
print $tb;
答案 1 :(得分:1)
对于这个简单的任务来说,模块并不是必需的。
use strict;
use warnings;
my @array = (
1, 999999991, 999999992,
2, 999999993, 999999994,
3, 999999995, 999999996,
);
while ( @array >= 3 ) {
printf "%-4s %-10s %s\n", splice @array, 0, 3;
}
<强>输出强>
1 999999991 999999992
2 999999993 999999994
3 999999995 999999996