我試圖以表格格式打印輸出。perl打印表格輸出
我的腳本:
use strict;
my @heading=("FN","SN","BP","SUBBN","LgcBT");
my @values=("1","0","Front","Mother Board","MIU");
print "\n\n";
&HEADING;
print "\n";
&VALUES;
print "\n\n";
sub HEADING {
foreach (@heading) {
my $lgth1=length($_);
printf "%3s","| ";
printf "%${lgth1}s",$_;
}
}
sub VALUES {
foreach (@values) {
my $lgth2=length($_);
printf "%3s","| ";
printf "%${lgth2}s",$_;
}
}
輸出:
| FN | SN | BP | **SUBBN** | LgcBT
| 1 | 0 | Front | **Mother Board** | MIU
我需要打印輸出的方式,如果值比則標題時間越長,自動調整航向至的價值的長度。
Hello Nathan,謝謝你的代碼。由於我是網絡人,你可以詳細說明一下我怎樣才能在我現有的腳本中使用提供的代碼,這是在最初的帖子....抱歉的麻煩... – Mahesh
@Mahesh:在你生成'@ lengths'數組,只需在'%3s'中使用'3'而不是'$ {lgth2}'和'$ {lgth1}'。 –
哦,我的上帝納坦...這真是太神奇了...非常感謝.....它工作...問候:Mahesh – Mahesh