[英]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.