具体用法是什么print
, printf
, and sprintf
在 Perl 中?
这三个关键字都用于打印目的,但有人可以简单地区分一下吗?
Short:
请参阅手册:
- http://perldoc.perl.org/functions/print.html http://perldoc.perl.org/functions/print.html
- http://perldoc.perl.org/functions/printf.html http://perldoc.perl.org/functions/printf.html
- http://perldoc.perl.org/functions/sprintf.html http://perldoc.perl.org/functions/sprintf.html
Long:
print
是默认的输出函数。它不进行格式化,但如果使用 Perl 调用,可能会附加换行符-l
:
print $foo;
print "Hello $world";
print $filehandle $something;
sprintf
是一个格式化程序,根本不执行任何打印:
$result = sprintf('The %s is %d', 'answer', 42);
printf
是相同的sprintf
,但实际打印结果:
printf 'This is question %d on %s', 36882022, 'StackOverflow';
See the sprintf文档 http://perldoc.perl.org/functions/sprintf.html有关有效占位符/格式字符串的更多详细信息。
从 5.10 开始,Perl 还支持say http://perldoc.perl.org/functions/say.html这基本上是一个print
再加上一个额外的\n
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)