Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2016-10-28 09:11 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (379 votes). Check out past polls.