gpt4 book ai didi

perl - 为什么 printf 和 sprintf 在仅给定数组时表现不同?

转载 作者:行者123 更新时间:2023-12-04 02:33:05 25 4
gpt4 key购买 nike

sub do_printf  { printf @_ }
sub do_sprintf { print sprintf @_ }

do_printf("%s\n", "ok"); # prints ok
do_sprintf("%s\n", "ok"); # prints 2

最佳答案

来自 perldoc on sprintf :

Unlike printf, sprintf does not do what you probably mean when you pass it an array as your first argument. The array is given scalar context, and instead of using the 0th element of the array as the format, Perl will use the count of elements in the array as the format, which is almost never useful.

关于perl - 为什么 printf 和 sprintf 在仅给定数组时表现不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2485106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com