作者sqrt1089 (李崩子)
看板Perl
标题[问题] print 跟printf
时间Wed May 25 13:57:20 2011
如题
printf "%-9s\t%5s\t%5s\n",'name','score1','score2';
输出长这样:
姓名 分数A 分数B
小王 88 90
就是名子会靠左对齐,数字会靠右对齐,
我想问的是如果用 print要如何达到相同的结果
因为我是把所有的字串先存成矩阵
ex push(@output,"$name\t$score1\t$score2\n");
print @output;
输出长这样:
姓名 分数A 分数B
小王 88 90
但是我只会加入 TAB键,所以有没有类似\t的分隔可以把 分数那边置右?
--
--
▂▂ ▂▂▂
▂▄▅▅▄▆█ _█◣
◢ (●) ◣/\\
丫 │◥  ̄◤
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.116.215.174
1F:推 abliou:也许你会需要write跟format搭配$^跟$= 05/25 14:32
2F:推 dryman:format+1 05/25 15:13
3F:→ dryman:或是你可以把所有的变数存进array而不是存字串进去 05/25 15:15
4F:推 liyih:sprintf 可以吗? 05/25 15:41
5F:推 frank1983:printf "%-9s\t%5s\t%5s\n", @$_ for (接下行) 05/26 03:20
6F:→ frank1983:map { [ split /\t/ ] } @output (这样可以吗?) 05/26 03:20
7F:推 abliou:楼上的前辈,如果有人考一百分这样适用吗? 05/26 08:39
8F:推 frank1983:你是在问我吗:-) ...应该没有差别吧~ 05/27 01:29
9F:→ sqrt1089:感谢frank大大了 05/27 17:20