我不明白 Perl read($buf) 函数如何能够修改 $buf 变量的内容。$buf 不是参考,因此参数由副本给出(根据我的 c/c++ 知识)。那么 $buf 变量是如何在调用者中被修改的呢?
是平局变量还是什么?关于 setbuf 的 C 文档对我来说也非常难以捉摸和不清楚
# Example 1
$buf=''; # It is a scalar, not a ref
$bytes = $fh->read($buf);
print $buf; # $buf was modified, what is the magic ?
# Example 2
sub read_it {
my $buf = shift;
return $fh->read($buf);
}
my $buf;
$bytes = read_it($buf);
print $buf; # As expected, this scope $buf was not modified