The built-in sprintf function has a prototype:
$ perl -e 'print prototype("CORE::sprintf")' $@
It treats the first argument as a scalar. Since you provided the @ARGV argument, it was forcibly converted to a scalar, passing the number of @ARGV elements @ARGV .
Since the printf function must support the syntax printf HANDLE TEMPLATE,LIST , as well as printf TEMPLATE,LIST , it cannot support the prototype. Therefore, he always considers his arguments as a flat list and uses the first element in the list as a template.
One way to make its second script work correctly is to call it as
$tmp = sprintf shift @ARGV, @ARGV
Another difference between printf and sprintf is that print sprintf adds $\ to the output, and printf doesn't (thanks, ysth).
mob
source share