程序中遇到一個問題,一個引用變量傳入函數中,如果賦值一個新的引用,則外部引用沒有改變,如果更改引用內容,則變量隨之改變,做個記錄,下次注意。
如下爲示例:
sub test1{
my $x = shift;
$x = {left=>undef, right=>undef, key=>123, parent=>undef,};
}
sub test2{
my $x = shift;
$x->{key} = 123;
}
$t = {left=>undef, right=>undef, key=>undef, parent=>undef,};;
use Data::Dumper ;
test1($t);
print Dumper $t;
test2($t);
print Dumper $t;
$VAR1 = {
'left' => undef,
'parent' => undef,
'right' => undef,
'key' => undef
};
$VAR1 = {
'left' => undef,
'parent' => undef,
'right' => undef,
'key' => 123
};