Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Answer: How do I completely remove an element from an array?

by OzVegan (Acolyte)
on Aug 28, 2009 at 03:16 UTC ( #791818=categorized answer: print w/replies, xml ) Need Help??

Q&A > arrays > How do I completely remove an element from an array? - Answer contributed by OzVegan

I'd iterate backwards through the array therefore avoiding the missing element syndrome when using an index counter. So if we were removing 1 and 3 from the following array...
my @array = qw( alpha beta gamma delta ); for ( my $index = $#array; $index >= 0; --$index ) { splice @array, $index, 1 if $array[$index] =~ /e/; # remove certain elements }

Log In?

What's my password?
Create A New User
[Corion]: Hi marto!
[Corion]: I just found out that in $current_top_prior ity_project , the part I am in is not even in the top three worries. That's somewhat bad, not because I'm happy with being a top worry but because that means that I don't even know how bad the rest ...
[Corion]: ... of the situation is :-)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2017-07-26 08:05 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (385 votes). Check out past polls.