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

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

( #791818=categorized answer: print w/ replies, xml ) Need Help??

Q&A > arrays > How do I completely remove an element from an array? 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 }

Comment on Answer: How do I completely remove an element from an array?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2014-12-26 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls