Sandy has asked for the wisdom of the Perl Monks concerning the following question:
Example:
Given a paired input ($a,$b), I need to test if the paired elements exist anywhere in the arrays...element @a @b 0 1 aa 1 2 aa 2 1 ab 3 1 ac 4 2 ac 5 2 ad 6 1 ac 7 2 ac
Obviously I could create a more intelligent system, but I wish to keep the code changes to a minimum, and the paired arrays are used throughout the entire code. That said, I want to keep them as is.
This is the current code
This works, but I find it kinda clunky. I've thought about 'greps' and 'maps' but I can't seem to come up with anything that is 'less' clunky.$found = 0; foreach $j (1..@a-1) { if ($a eq $a[$j] && $b eq $b[$j]) { $found = 1; last; } } unless ($found) {do something}
Any ideas?
Sandy
UPDATE: fixed typo in code snippet
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding a match between two paired arrays
by broquaint (Abbot) on Jan 08, 2004 at 15:40 UTC | |
by Zed_Lopez (Chaplain) on Jan 08, 2004 at 15:49 UTC | |
by duff (Parson) on Jan 08, 2004 at 15:53 UTC | |
|
Re: Finding a match between two paired arrays
by duff (Parson) on Jan 08, 2004 at 15:45 UTC | |
|
Re: Finding a match between two paired arrays
by ysth (Canon) on Jan 08, 2004 at 17:10 UTC | |
by Anonymous Monk on Jan 08, 2004 at 18:24 UTC | |
by ysth (Canon) on Jan 08, 2004 at 19:49 UTC | |
|
Re: Finding a match between two paired arrays
by antirice (Priest) on Jan 08, 2004 at 16:30 UTC | |
|
Re: Finding a match between two paired arrays
by kesterkester (Hermit) on Jan 08, 2004 at 15:52 UTC | |
|
Re: Finding a match between two paired arrays
by Sandy (Curate) on Jan 08, 2004 at 20:15 UTC |