in reply to See if arrays match

Greetings anonymous,

The following was copied from the Perl Cookbook, Recipe 4.8 by Tom Christiansen & Nathan Torkington; ISBN 1-56592-243-3.

@a = (1, 3, 5, 6, 7, 8); @b = (2, 3, 5, 7, 9); foreach $e (@a, @b) { $union{$e}++ && $isect{$e}++ } @union = keys %union; @isect = keys %isect;

-gryphon
code('Perl') || die;

Replies are listed 'Best First'.
Re: Re: See if arrays match
by ehdonhon (Curate) on Jul 23, 2002 at 21:39 UTC

    Looks like that only works if you are guaranteed that no items appear in the same list more than once. It would not work properly for this:
    @a = ( 1, 2, 3, 4, 2 );
    @b = ( 1, 3, 5 );