以下两个简单的Perl程序行为不同:
#file1
printf @ARGV;
#file2
$tmp = sprintf @ARGV;
print $tmp;
$> perl file1 "hi %04d %.2f" 5 7.12345
#output: hi 0005 7.12
$> perl file2 "hi %04d %.2f" 5 7.12345
#output: 3
Why is the difference? I had thought the two programs are equivalent. Wonder if there is a way to make file2 (using "sprintf") to behave like file1.
$tmp = &CORE::sprintf(@ARGV);
如果您不想修改@ARGV
。 - Suicsprintf $ARGV[0], @ARGV[1..$#ARGV]
- LeoNerd