[plug] Perl: Intersection of two arrays?

Trevor Phillips T.Phillips at murdoch.edu.au
Wed Jun 25 16:22:09 WST 2003


On Wednesday 25 June 2003 15:18, Simon Newton wrote:
> 
> you could shorten it a bit:
>
> sub SetIntersection
> {
>    my %count = ();
>    foreach (@{$_[0]}) { $count{$_} |= 1; };
>    foreach (@{$_[1]}) { $count{$_} |= 2; };
>    return grep { $count{$_} == 3 } keys %count;
> }
>
> at the expense of becomming unreadable :)

Bah, I can still read it. And it's ever so marginally faster, too! ^_^

> > I still wonder if a custom function written in C could do things a chunk
> > faster. ^_^
>
> If you really wanted speed, you wouldn't be using Perl.

Speed of development time is also a factor.
As is keeping my brain from dribbling out my ears.

> You might want to take a look at Inline::C . I've never used it but I'd
> say its what your after.

I keep meaning to look into things like that. OTOH, I'm always finding out new 
joys of optimisation, where days coding can give a marginal improvement (or 
make things slower), and other simpler fixes can give a bigger boost. And 
Perl is quite good at it too, with optimisations under the bonnet and 
leveraging of existing efficient C code...

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