我有一個包含一組元素的數組。元素的順序是不相關的 - 我使用一個數組,因爲它是我在Perl中知道的最簡單的數據結構。在Perl中刪除數組元素的「正確」方法是什麼?
my @arr = ...
while (some condition) {
# iterate over @arr and remove all elements which meet some criteria
# (which depends on $i)
}
我知道splice()
,但我認爲迭代時使用它並不好。數組元素的delete
似乎不推薦使用。也許在@arr
本身上使用grep
(@arr = grep {...} @arr
)?
這裏的最佳做法是什麼?
也許使用散列(雖然我真的不需要它)?
的可能重複[什麼是刪除從Perl中的數組值的最佳方法?(http://stackoverflow.com/questions/174292/什麼 - 是最最好的方式到刪除-a值從 - 一個陣列式-perl的) – 2014-04-10 20:53:10