我不明白Perl讀取($ buf)函數是如何修改$ buf變量的內容的。 $ buf不是一個引用,所以參數是由copy(來自我的c/C++知識)給出的。那麼在調用者中如何修改$ buf變量?perl read()函數和不是ref的緩衝區背後有什麼魔力?
這是一個領帶變量或什麼?約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
非常感謝指向相關文檔的指針,並且您的技巧很有用,非常感謝 – 2010-06-10 06:37:15