print is
the default output function. It does no formatting but may append a line break if Perl is called with -l:
print $foo;
print "Hello $world";
print $filehandle $something;
sprintf is
a formatter and doesn't do any printing at all:
$result = sprintf('The %s is %d', 'answer', 42);
printf is
the same as sprintf,
but actually prints the result:
printf 'This is question %d on %s', 36882022, 'StackOverflow';
本文介绍了Perl语言中print、sprintf及printf三个函数的基本用法。print用于输出数据,不进行格式化,但在使用-l选项时会在末尾添加换行符;sprintf用于字符串格式化,不执行实际打印操作;printf则结合了两者功能,既能格式化输出又会将结果打印出来。

7087

被折叠的 条评论
为什么被折叠?



