【发布时间】:2021-06-18 13:06:18
【问题描述】:
我是 Perl 的新手。我卡在格式化和显示数据。我需要从 CSV 文件中读取数据并以正确的格式将其打印在屏幕上。每列的宽度由列中存在的元素的最大长度决定。
my $file = $ARGV[0] or die;
open(my $data, '<', $file) or die;
my $max = 0;
while (my $line = <$data>)
{
chomp $line;
# Split the line and store it
# inside the words array
my @words = split ", ", $line;
my @C = split( ",", $line);
#$max = length $C[1];
print ("%08c", "$C[2]\n");
for (my $i = 0; $i <= 2; $i++)
{
#print "$words[$i] ";
}
#print "\n";
}
print "maximum:max($max)\n";
【问题讨论】:
-
你能展示一个输入样本和相应的预期输出吗?
-
如果您在列中有各种元素,例如 {apple, bat, cat, dance} 现在所有元素的宽度应该等于跳舞长度,以便在终端上看起来正确。
-
请用示例更新问题。