我有两个打印声明,一个接一个。
print("Number of cars");
printf("%10d","$somevariable");
print("Number of blue cars");
printf("%10d","$somevariable");
print("Number of red cars");
printf("%10d","$somevariable");
我的问题是变量的值不会垂直对齐。它看起来像这样
Number of Cars 0
Number of blue Cars 0
Number of Red Cars 0
有没有办法将它们对齐到水平线上的某个点?例如,始终将所有内容打印在右侧80个空格处?
编辑:输出到终端。
干杯
答案 0 :(得分:3)
在printf中包含标签:
printf("%-20s%10d\n","Number of cars", $somevariable)
printf("%-20s%10d\n","Number blue of cars", $someothervariable)
答案 1 :(得分:0)
对于更复杂的布局,请考虑Text::SimpleTable,Text::Table或similar