[plug] Perl: Intersection of two arrays?

Trevor Phillips T.Phillips at murdoch.edu.au
Tue Jun 24 17:23:39 WST 2003


Given two arrays (in Perl) with string values, I need to derive an array of 
the elements in both. I'd like to do this quickly, too. ^_^

I know I could do it using something like:

   @intersect = grep { $s1=$_; ((grep { $s1 eq $_ } @set2)?1:0) } @set1;

... but is there any Perl routine or popular third-party module with a nice 
fast C equivalent version which would be faster?

Yes, I've looked through the Perl manpage and CPAN, etc... Closest I found was 
complex OO objects & methods to do almost this. Just wondering if I missed 
something else that was lean & useable...

-- 
. Trevor Phillips             -           http://jurai.murdoch.edu.au/ . 
: Web Technical Administrator     -          T.Phillips at murdoch.edu.au : 
| IT Services                        -              Murdoch University | 
 >--------------------------------------------------------------------<
| On nights such as this, evil deeds are done. And good deeds, of     /
| course. But mostly evil, on the whole.                             /
 \      -- (Terry Pratchett, Wyrd Sisters)                          /



More information about the plug mailing list