[geeks] Programming question.

David Cantrell david at cantrell.org.uk
Tue Apr 2 03:39:45 CST 2002


On Tue, Apr 02, 2002 at 10:16:45AM +0100, David Cantrell wrote:
> On Mon, Apr 01, 2002 at 07:58:16PM -0600, Bill Bradford wrote:
> > Okay, so far, I havent been able to figure out a way to do this, so any
> > suggestions would be appreciated.
> > 
> > Compare two lists.  List A, and List B.
> > I want to be able to then extract a list of 
> > elements of List B that are *not* in List A.
> 
> In perl ...
> 
> use Quantum::Superpositions;
> @C = eigenstates(any(@B) != all(@A));

Oh, sorry.  You wanted a SENSIBLE solution? :-)

my @a = (1,3,5,7,9);
my @b = (0,1,2,3,4,5,6,7,8,9);
my @c = ();

my %a = map { ($_, 1) } @a;
foreach (@b) { push @c, $_ unless($a{$_}) }

print join (', ', @c);

I'm assuming you aren't interested in uniqueness, so if list A contains FOO
once and list B contains FOO twice, the FOO in list A will cancel both the
FOOs in list B.

-- 
David Cantrell | Benevolent Dictator | http://www.cantrell.org.uk/david

  Longum iter est per praecepta, breve et efficax per exempla.
      -- Seneca Philosophus, Epistulae



More information about the geeks mailing list