脚本宝典收集整理的这篇文章主要介绍了perl之print,printf,sprintf使用案例详解,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
详细用法,可以查看PErl用户手册。
perldoc -f PRint
perldoc -f printf
perldoc -f sprintf
他们各自支持的命令格式,都有三四种。但是常用的,也就一两种。
常用:
print LIST
print FILEHANDLE LIST
不常用(主要是因为隐含的细节,会导致阅读上的障碍吧):
print FILEHANDLE
print
print $foo; print "Hello $world"; print $filehandle $something;
常用:
printf FORMAT, LIST
printf FILEHANDLE FORMAT, LIST
不常用(主要是因为隐含的细节,会导致阅读上的障碍吧):
printf FILEHANDLE
printf
printf 'This is question %d on %s', 36882022, 'StackOverflow';
命令格式,只有一种:
sprintf FORMAT, LIST
$result = sprintf('The %s is %d', 'answer', 42);
另外,sprinf还有很多复杂的用法,个人不常用。具体参考perldoc -f sprintf
例如:
printf '%2$d %1$d', 12, 34; # prints "34 12" printf '%3$d %d %1$d', 1, 2, 3; # prints "3 1 1"
command | description |
---|---|
打印信息,可以输出到文件里 | |
printf | 可以整理信息的格式,可以输出到文件里。与sprintf类似,区别是可以打印 |
sprintf | 可以整理信息的格式。与printf类似,区别是仅仅用于字符串的格式化,没有任何print效果。 |
http://perldoc.perl.org/functions/print.html
http://perldoc.perl.org/functions/printf.html
http://perldoc.perl.org/functions/sprintf.html
到此这篇关于perl之print,printf,sprintf使用案例详解的文章就介绍到这了,更多相关perl之print,printf,sprintf使用内容请搜索脚本宝典以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本宝典!
@H_937_126@ 您可能感兴趣的文章:以上是脚本宝典为你收集整理的perl之print,printf,sprintf使用案例详解全部内容,希望文章能够帮你解决perl之print,printf,sprintf使用案例详解所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。