Removing entries in array based on another array

L

Leif Wessman

I would like to remove the complete entry in an array if the value of
the entry matches any of the values in another array.

Like this:

use strict;
use warnings;

my @names ("bob","barney","-","lisa","UNKNOWN");
my @delete ("-","unknown");

....

result should be that @names contains only bob, barney and lisa.
Thanks for any input!

Leif
 
A

Anno Siegel

Gunnar Hjalmarsson said:
That's a Frequently Asked Question.

perldoc -q duplicate

You are expected to check the Perl FAQ before posting a question here.

That finds "How can I remove duplicate elements from a list or array?",
which doesn't deal with the OPs problem, tough it might help.
The one that deals with the problem directly is found through

perldoc -q difference

"How do I compute the difference of two arrays?"

Anno
 
G

Gunnar Hjalmarsson

Anno said:
That finds "How can I remove duplicate elements from a list or
array?", which doesn't deal with the OPs problem, tough it might
help.

Of course, thanks! Sorry Leif for pointing you to the wrong FAQ entry.
Maybe I should check the FAQ before posting such a comment... ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top