Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: An efficient way to remove an element from an array

by AnomalousMonk (Canon)
on Aug 06, 2012 at 19:10 UTC ( #985801=note: print w/replies, xml ) Need Help??

in reply to An efficient way to remove an element from an array

Here's an 'efficient' method if you're completely unconcerned about maintaining array order. (This was published by someone else recently in response to a strikingly similar question.)

>perl -wMstrict -le "my @ra = (0, 1, 2, 3, 4, 5); print qq{@ra}; for my $i (2, 0, -2, -1) { $ra[$i] = $ra[-1]; --$#ra; print qq{removed element at index $i: @ra}; } " 0 1 2 3 4 5 removed element at index 2: 0 1 5 3 4 removed element at index 0: 4 1 5 3 removed element at index -2: 4 1 3 removed element at index -1: 4 1

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985801]
[TStanley]: I am heading to Arlington, Virginia next week, then I get to spend an entire week at home. Looking forward to that as I will have spent 7 weeks on the road by the end of next week
[talexb]: That's a long road trip. I haven't travelled for business in years.

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2017-06-23 14:23 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (548 votes). Check out past polls.