2012-11-27 45 views
2

我正在使用XML :: DOM處理Perl代碼。perl中的返回值XML :: DOM

我在Perl的幫助(XML :: DOM :: Node)中發現,聲明如下。

@list = $node->getChildNodes;  # returns a perl list 
$nodelist = $node->getChildNodes; # returns a NodeList (object reference) 
for my $kid ($node->getChildNodes) # iterate over the children of $node 

如果我通過它在我的函數如下。

&myfunction($node->getChildNodes) 

我沒有得到列表的參考。

有沒有什麼辦法可以用out來聲明臨時標量變量,如下所示。

my $tmp=$node->getChildNodes; 
&myfunction($tmp) 

謝謝。

回答

1
myfunction([ $node->getChildNodes ]) 

myfunction(scalar $node->getChildNodes) 

第二個避免創建一個新的數組和一個新的引用,但第一個可能會更清晰。


PS —你爲什麼要告訴Perl來忽略myfunction原型?不要使用&

+0

它的作品!謝謝。 – NewToUnix

+0

如果這回答你的問題,請檢查它旁邊的標記。歡迎來到StackOverflow! – ikegami