當$ perlobj傾倒這個我目前有以下無法正確合併哈希
# $dog, $cat, $rat are all hash refs
my %rethash = ('success' => 'Your Cool');
my %ref ={ 'dog' => $dog, 'cat' => $cat, 'mouse' => $rat,
'chicken' => '' };
my $perlobj = (\%ref,\%rethash);
是結果
$VAR1 = {
'success' => 'Your Cool'
};
然而,當警告使我得到以下信息
Useless use of reference constructor in void context at ..
我意識到如何使用{}分配%ref存在一些可怕的錯誤,這段代碼有什麼問題?我似乎無法擺脫這種警告....
編輯: 好吧,我想我想通了,怎麼回事,
my $perlobj = (\%ref,\%rethash);
這不會合並,但在$ perlobj成爲結果參考%rethash,在閱讀你的回答之後,這是顯而易見的。
當你使用'()'創建'%ref'時使用'{}' – RobEarl
你也希望'我的%perlobj =(%ref,%rethash);' – RobEarl
可能的重複[如何在Perl中結合散列?](http://stackoverflow.com/questions/350018/how-can-i -combine-hashes-in-perl) – RobEarl