繁体   English   中英

Perl脚本-在终端输出中实时创建的表

[英]Perl script - tables created in real time in terminal output

我的脚本在终端输出中的不同行上打印数据,如下所示:

Name: Paul Surname: Doe Age:34
Name: Paulo Surname: Doeson Age:28 
Name: Paulinho Surname: Docsone Age:5
Name: Paulmen Surname: Doee Age:12
Name: Paulchen Surname: Dooe Age:31

我希望将所有数据分为几列,并以条形显示,如下所示:

Name: Paul     Surname: Doe     Age:34
Name: Paulo    Surname: Doeson  Age:28
Name: Paulinho Surname: Docsone Age:5 
Name: Paulmen  Surname: Doee    Age:12 
Name: Paulchen Surname: Dooe    Age:31 

我注意到输出不能被缓冲或存储。 我想在运行脚本时实时实现这一目标。 有什么技巧可以做到这一点? 例如在HTML表格中指定单元格的宽度?

编辑
真正的示例代码:

@arr = q(Name: Paul Surname: Doe Age:34, Name: Paulo Surname: Doeson Age:28, Name: Paulinho Surname: Docsone Age:5, Name: Paulmen Surname: Doee Age:12, Name: Paulchen Surname: Dooe Age:31);

foreach (@arr) {
  # here should be our trick to creating columns
  print $_ # should be print element in columns (without buffering). print now, not after loop end. 
}

我首先想到的是Perl格式 它是内置的,为您提供了一整套格式化输出的方法。 看看它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM