narashima has asked for the wisdom of the Perl Monks concerning the following question:
Revered monks,
I am trying to compare 2 simple arrays @file and @file2.
After the comparision I need:
- matched elments
- elements in @file1 not in @file2 and
- elements in @file2 not in @file1
I am using the following code... Is this the best way of doin it??? is there a optimization or even a direct function for this?
%seen = (); @seen{ @file1 } = (); @infile1only = grep { ! exists $seen{$_} } @file2; %seen =(); @seen{ @file2 } = (); @infile2only = grep { ! exists $seen{$_} } @file1; @matched = grep { exists $seen{$_} } @file1;
thanks,
narashima
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: optimal way of comparing 2 arrays
by chester (Hermit) on Oct 19, 2005 at 19:57 UTC | |
Re: optimal way of comparing 2 arrays
by Roy Johnson (Monsignor) on Oct 19, 2005 at 19:48 UTC | |
Re: optimal way of comparing 2 arrays
by dragonchild (Archbishop) on Oct 19, 2005 at 19:49 UTC | |
Re: optimal way of comparing 2 arrays
by NetWallah (Canon) on Oct 19, 2005 at 21:01 UTC | |
Re: optimal way of comparing 2 arrays
by jfroebe (Parson) on Oct 19, 2005 at 20:58 UTC | |
by narashima (Beadle) on Oct 19, 2005 at 21:20 UTC | |
Re: optimal way of comparing 2 arrays
by blazar (Canon) on Oct 20, 2005 at 10:13 UTC | |
by narashima (Beadle) on Oct 20, 2005 at 13:51 UTC | |
by blazar (Canon) on Oct 20, 2005 at 15:00 UTC | |
Re: optimal way of comparing 2 arrays
by graff (Chancellor) on Oct 20, 2005 at 01:34 UTC |
Back to
Seekers of Perl Wisdom