in reply to Comparing two file in Arrays

The Perl Cookbook has a section on working with pairs of arrays to find intersections, differences, etc.

The following is one piece of code it contains - using a temporary hash:

@a = (1, 3, 5, 6, 7, 8); @b = (2, 3, 5, 7, 9); @union = @isect = (); %union = %isect = (); %count = (); foreach $e (@a, @b) { $union{$e}++ && $isect{$e}++ } @union = keys %union; @isect = keys %isect;
Steve
---
steve.org.uk

Replies are listed 'Best First'.
Re: Re: Comparing two file in Arrays
by graff (Chancellor) on Jan 03, 2004 at 04:25 UTC
    That is a nice, slick/quick method -- but it will produce false positives for intersections if either array happens to contain multiple elements with the same value (e.g. in your example, if @a contained two elements with a value of 6).