Removing entries in array based on another array

Discussion in 'Perl Misc' started by Leif Wessman, Aug 29, 2004.

  1. Leif Wessman

    Leif Wessman Guest

    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
     
    Leif Wessman, Aug 29, 2004
    #1
    1. Advertising

  2. Gunnar Hjalmarsson, Aug 29, 2004
    #2
    1. Advertising

  3. Leif Wessman

    Anno Siegel Guest

    Gunnar Hjalmarsson <> wrote in comp.lang.perl.misc:
    > Leif Wessman wrote:
    > > 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.

    >
    > 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
     
    Anno Siegel, Aug 29, 2004
    #3
  4. Anno Siegel wrote:
    > Gunnar Hjalmarsson wrote:
    >> Leif Wessman wrote:
    >>> 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.

    >>
    >> 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.


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

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Aug 29, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sri2097
    Replies:
    4
    Views:
    580
    sri2097
    Jan 10, 2006
  2. Replies:
    2
    Views:
    558
    Andy Dingley
    Dec 6, 2006
  3. Replies:
    1
    Views:
    449
    Paul Lutus
    Dec 6, 2006
  4. Don Bruder
    Replies:
    3
    Views:
    977
    spikeysnack
    Aug 3, 2010
  5. Thomas Adam

    Removing "nil" entries from array

    Thomas Adam, Sep 19, 2003, in forum: Ruby
    Replies:
    4
    Views:
    123
    Jason Creighton
    Sep 19, 2003
Loading...

Share This Page