develooper Front page | perl.beginners | Postings from February 2009

Re: Reading 2 array lists

Thread Previous | Thread Next
From:
Gunnar Hjalmarsson
Date:
February 19, 2009 11:27
Subject:
Re: Reading 2 array lists
Message ID:
20090219192702.313.qmail@lists.develooper.com
Chas. Owens wrote:
> On Thu, Feb 19, 2009 at 10:20, mritorto <mritorto@gmail.com> wrote:
>> owen,
>>
>> How do you use the List::Compare module is the same as array::compare?
> snip
> 
> List::Compare can be found in CPAN*.  Here is you program rewritten to
> use it (this is not what I would do):

We know. ;-)

<snip>

> my @atlas = <$atlas>;
> my @isis  = <$isis>;
> 
> my $comparison = List::Compare->new(\@atlas, \@isis);
> 
> print $comparison->get_symmetric_difference;

It's worth noting that if the so called symmetric difference is 
sufficient, the same result is achieved if you use the approach suggested in

     perldoc -q difference.+arrays

Actually, you only need one single hash:

     my %count;
     $count{$_}++ while <$atlas>;
     $count{$_}++ while <$isis>;
     print sort map { $count{$_} == 1 ? $_ : () } keys %count;

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About