[英]Perl script - tables created in real time in terminal output
My script prints data on separate lines in terminal output, it looks like this: 我的脚本在终端输出中的不同行上打印数据,如下所示:
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
And I would like all data to be divided into columns and displayed equally in bars, as below: 我希望将所有数据分为几列,并以条形显示,如下所示:
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
I note that the output can not be buffered or stored. 我注意到输出不能被缓冲或存储。 I would like to achieve this in real time while running the script.
我想在运行脚本时实时实现这一目标。 Are there any tricks to achieve this?
有什么技巧可以做到这一点? Something like specifying the width of a cell in an HTML table?
例如在HTML表格中指定单元格的宽度?
EDIT 编辑
Really EXAMPLE code: 真正的示例代码:
@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.
}
First thing that comes into my mind are Perl formats . 我首先想到的是Perl格式 。 It's built-in and give's you a whole bunch of means for formatting output.
它是内置的,为您提供了一整套格式化输出的方法。 Have a look at it.
看看它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.