具有以下简短脚本:

use strict;
use warnings;

my $file = $0;
sub mystat { stat(@_); }

print "perl: $]\n";
print "the $file stats (direct call): @{[ stat($file) ]}\n";
my @statval = mystat($file);
print "the $file stats (mystat call): @statval\n";


在perl 5.22上的代码显示了预期的结果(至少按我的预期):

perl: 5.022000
the mystat stats (direct call): 16777218 28103610 33188 1 501 0 0 230 1443094200 1443094192 1443094192 4096 8
the mystat stats (mystat call): 16777218 28103610 33188 1 501 0 0 230 1443094200 1443094192 1443094192 4096 8


使用5.23.3打印

perl: 5.023003
the mystat stats (direct call): 16777218 28103610 33188 1 501 0 0 230 1443094194 1443094192 1443094192 4096 8
the mystat stats (mystat call):


怎么了?

最佳答案

似乎stat()不喜欢将数组作为参数传递,但是在传递单个标量时,它可以按预期工作,

sub mystat { stat($_[0]); }

08-26 21:24