Re: [請益] 關於"變數參考"問題

看板Perl作者 (C語言)時間12年前 (2012/12/12 13:10), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
不好意思 從你的 code 看不出要幹嘛.. 這樣子好嗎ꀠ把資料都放進 newlist 然後 $targetdomain->{list} 存 newlist ref 最後解參考 $targetdomain->{list} 印出你的 12345 1 #!/usr/bin/perl 2 3 @listref = (1,2,3,4,5); 4 5 foreach my $bb ( @listref ) 6 { 7 push( @newlist, $bb ); 8 } 9 $targetdomain->{list}=\@newlist; 10 print @{ $targetdomain->{list} }; 11 ※ 引述《kuangs (kuangs)》之銘言: : 大家好 : 目前小弟遇到一個問題 : 假設我的資料 : @listref= 1,2,3,4,5,6 : foreach my $bb ( @listref ) : { : $newlist{list}=$bb; : push( @newlist, \%newlist); : } : $targetdomain->{list}=\@newlist; : print $targetdomain; : 印出來的結果 : 我想要的應該是 1 2 3 4 5 : 實際上卻是 5 5 5 5 5 : 我知道原因出在哪 應該是參考變數的問題 : 五個資料都是參考同一個%newlist : 而最後一個輸入的數值為5 : 所以才會印出 五個5 : 但是我卻不知怎麼解決!! 請各位高手幫幫忙!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.43.204.80
文章代碼(AID): #1Go89VNE (Perl)
討論串 (同標題文章)
本文引述了以下文章的的內容:
以下文章回應了本文
0
3
完整討論串 (本文為第 2 之 3 篇):
0
3
文章代碼(AID): #1Go89VNE (Perl)