Perl Christmas Quiz

Peter Corlett abuse at cabal.org.uk
Fri Dec 12 14:01:32 GMT 2008


On Fri, Dec 12, 2008 at 01:18:24PM +0000, Hakim Cassimally wrote:
[...]
> The question isn't specific about how the output should look if it a key
> doesn't appear in both arrays, or if n==m.

It does. It asks for the "intersect", which is the set theory way of saying
"those elements that appear in both sets, and no others".

Here's my attempt:

sub intersect{my%x;$x{$_}++for(@{+shift});grep{$x{$_}&&$x{$_}--}@{+shift};}

Let the golfing begin!



More information about the london.pm mailing list