我在寫一個子例程,它打印另一個數組中的非冗餘元素的數組。清空數組內循環,同時在PERL中使用推送
這段代碼在我的子程序中。
foreach (@old_table) { push(@new_table, $_) unless ($seen{$_}++); }
print "@new_table" . "\n";
然後我打電話給我在一個循環子程序我的主要程序中,對於第一次迭代是確定,我的新表中包含我的舊錶的發生。 但之後@new_table
保留過去迭代的元素,並且打印結果爲false。
我試圖清空@new_table
我的子程序內,這樣
@new_table =();
foreach (@old_table) { push(@new_table, $_) unless ($seen{$_}++); }
print "@new_table" . "\n";
但後來我@new_table
成爲所有迭代空除了第一個。
這是什麼問題,我該如何解決它?