On Jul 21, [EMAIL PROTECTED] said:

>I have 2 lists of companies, not neccessarly in order, and i want to produce
>a list of companies which apear in both lists.

This is in the FAQ -- if you type 'perldoc -q intersection', you'll get an
answer from the FAQ about finding the intersection of two arrays.

The simplest approach is to use hashes (if at all possible, INSTEAD of
your arrays).  If you already have arrays, then it's probably easiest just
to do the following:

  my @set_a = (...);
  my @set_b = (...);
  my (%companies, @in_both);

  # first, we make each string in @set_a
  # a key in the %companies hash
  @companies{ @set_a } = ();

  # now, we go through @set_b, and if the string
  # exists as a key in the %companies hash, we
  # know it's also in @set_a
  @in_both = grep exists $companies{$_}, @set_b;

The FAQ provides a different, but more extensible, approach.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to