Difference between printf, print, and sprintf in Perl?

来源:互联网 发布:openstack的网络配置 编辑:程序博客网 时间:2024/05/23 13:16

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';
0 0