- 论坛徽章:
- 0
|
原帖由 ExclusivePig 于 2009-9-10 14:45 发表 ![]()
第一次来,发现国内真正能够在perl方面答疑解惑的地方只有网络了。
希望各位不吝赐教。。。
问题如下:
@output = qw(111 222 333);
printf @output;
printf "output";
为什么2句printf输出结 ...
perldoc -f printf
printf FILEHANDLE FORMAT, LIST
printf FORMAT, LIST
Equivalent to "print FILEHANDLE sprintf(FORMAT, LIST)", except that "$\" (the output record separator) is not appended. The first argument of the list will be interpreted as the "printf" format. See "sprintf" for an explanation of the format argument. If "use locale" is in effect, the character used for the decimal point in formatted real numbers is affected by the LC_NUMERIC locale. See perllocale.
Don't fall into the trap of using a "printf" when a simple "print" would do. The "print" is more efficient and less error prone.
第一个printf将@output的第一个元素作为格式化控制串, 相当于"printf 111, 222, 333",
后面两个元素并没有在格式化控制串中作声明,所以只输出111;
第二个printf将"@output"作为格式化控制串,相当于printf "111 222 333", 故输出111 222 333 |
|