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

RE: Removing certain elements from an array

by Boogman (Scribe)
on Aug 24, 2000 at 20:50 UTC ( [id://29453]=note: print w/replies, xml ) Need Help??


in reply to Removing certain elements from an array

Use the splice function. From perlfunc:
splice ARRAY,OFFSET,LENGTH,LIST Removes the elements designated by OFFSET and LENGTH from an array, and replaces them with the elements of LIST, if any.
If you don't specify LIST, it just removes the specified elements from the array and "scrunches" the rest of the array together.

Update: Oh and if you want have a list of them you wanted to remove, you would probably want to do something like splice( @array, $_, 1 ) foreach ( @elementsToDelete ); And @elementsToDelete would have to be sorted in descending order as btrott mentions.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://29453]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 04:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found