Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Remove elements from an array

by revdiablo (Prior)
on Nov 23, 2004 at 18:04 UTC ( [id://409948]=note: print w/replies, xml ) Need Help??


in reply to Remove elements from an array

As ikegami says, you should use grep. He gives a good example for excluding elements based on a regular expression, but you might also want to exclude elements based on string equality (which would be far faster, though a different algorithm would probably be even better):

my @new = grep { $_ ne "certain string" } @old;

Or, perhaps you want to search for a substring:

my @new = grep { index($_, "certain string") == -1 } @old;

Just trying to give you some more ideas of how you can use grep... HTH

Update: no fair! ikegami updated his post in the time while I was posting this. Cheater. :-)

Log In?
Username:
Password:

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

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

    No recent polls found