I have an array containing a set of elements. The order of elements is irrelevant - I use an array since it's the simplest data structure I know in Perl.
my @arr = ...
while (some condition) {
# iterate over @arr and remove all elements which meet some criteria
# (which depends on $i)
}
I know of splice()
but I think it's not good using it while iterating. delete
for array elements seems deprecated. Perhaps use grep
on @arr
into itself (@arr = grep {...} @arr
)?
What is the best practice here?
Perhaps use a hash (although I don't really need it)?