CaptainF has asked for the wisdom of the Perl Monks concerning the following question:
I have many pairs of arrays that I need to compare for a simple set of criteria element by element. There is a premium on speed.
I have arrays that are something like:...and simply need to evaluate the first index position where a simple set of criteria are met (e.g., $a[3] ne $b[3] and $a[3] ne 'x' and b[3] ne 'x'). In my example, the correct answer would be element 3.@a = qw(a b c b c); @b = qw(a x c d d);
I've tried a variety of simple solutions of the form:
for(0..$#a){ if($a[$_] eq $b[$_] and $a[$_] ne 'x' ){ etc. etc. }elsif( ){ } }
etc. but that is absolutely clobbering performance (array sizes are on the order of 1000 elements, but I have approximately 1X10^12 pairs of arrays to compare (but not all in memory!).
Anyone have a suggestion?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: speedy way to compare elements in pairs of arrays?
by jethro (Monsignor) on May 26, 2009 at 09:21 UTC | |
by AnomalousMonk (Archbishop) on May 26, 2009 at 09:31 UTC | |
|
Re: speedy way to compare elements in pairs of arrays?
by CountZero (Bishop) on May 26, 2009 at 09:21 UTC | |
|
Re: speedy way to compare elements in pairs of arrays?
by almut (Canon) on May 26, 2009 at 08:50 UTC | |
|
Re: speedy way to compare elements in pairs of arrays?
by holli (Abbot) on May 26, 2009 at 08:55 UTC | |
|
Re: speedy way to compare elements in pairs of arrays?
by graff (Chancellor) on May 27, 2009 at 02:50 UTC | |
|
Re: speedy way to compare elements in pairs of arrays?
by CaptainF (Initiate) on May 28, 2009 at 17:40 UTC |