看板 Perl 關於我們 聯絡資訊
不好意思 從你的 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