Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
What I need to do is search the DB array for matching values from the Input array. So to produce an output similar to this:From DB AB1/1 AB1/5 AB2/5 From Input AB1/1 AB1/2 AB1/5 AB1/6 AB1/9 AB2/2 AB2/5 AB2/6 AB2/9 AB2/13
So I wrote this simple script:AB1/1 : Found AB1/1 AB1/2 : NotFound AB1/2 AB1/5 : Found AB1/5 AB1/6 : NotFound AB1/6 AB1/9 : NotFound AB1/9 AB2/2 : NotFound AB2/2 AB2/5 : Found Ab2/5 AB2/6 : NotFound Ab2/6 AB2/9 : NotFound AB2/9 AB2/13 : NotFound AB2/13
Which produced this incorrect output!#! c:/perl/bin/perl.exe # use strict; use warnings 'all'; my @NotFound; my @DB = qw(AB1/1 AB1/5 AB2/5); print "\nFrom DB\n"; for my $DBData (@DB) { print "$DBData\n"; } print "\nFrom Input\n"; my @Input = qw(AB1/1 AB1/2 AB1/5 AB1/6 AB1/9 AB2/2 AB2/5 AB2/6 AB2/9 A +B2/13); for my $InputData (@Input) { print "$InputData\n"; } ################################################## print "\nSearching\n"; for my $DBData (@DB) { for my $InputData (@Input) { if ("$DBData" eq "$InputData") { print "$InputData : Found $DBData\n"; last; } else { print "$InputData : NotFound $DBData\n"; } } } print "\nSize of NotFound Array $#NotFound\n";
I have spent sometime thinking about a solution for it, but the best I can produce is the above output.From DB AB1/1 AB1/5 AB2/5 From Input AB1/1 AB1/2 AB1/5 AB1/6 AB1/9 AB2/2 AB2/5 AB2/6 AB2/9 AB2/13 Searching AB1/1 : Found AB1/1 AB1/1 : NotFound AB1/5 AB1/2 : NotFound AB1/5 AB1/5 : Found AB1/5 AB1/1 : NotFound AB2/5 AB1/2 : NotFound AB2/5 AB1/5 : NotFound AB2/5 AB1/6 : NotFound AB2/5 AB1/9 : NotFound AB2/5 AB2/2 : NotFound AB2/5 AB2/5 : Found AB2/5 Size of NotFound Array -1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: searching 2 arrays
by Zaxo (Archbishop) on Oct 19, 2005 at 12:06 UTC | |
by sauoq (Abbot) on Oct 19, 2005 at 16:30 UTC | |
by Anonymous Monk on Oct 19, 2005 at 13:24 UTC | |
by VSarkiss (Monsignor) on Oct 19, 2005 at 14:41 UTC | |
|
Re: searching 2 arrays
by virtualsue (Vicar) on Oct 19, 2005 at 12:09 UTC | |
|
Re: searching 2 arrays
by pg (Canon) on Oct 19, 2005 at 12:39 UTC | |
by liverpole (Monsignor) on Oct 19, 2005 at 12:47 UTC | |
|
Re: searching 2 arrays
by liverpole (Monsignor) on Oct 19, 2005 at 12:34 UTC | |
|
Re: searching 2 arrays
by inman (Curate) on Oct 19, 2005 at 13:19 UTC | |
|
Re: searching 2 arrays
by Rajeshk (Scribe) on Oct 27, 2005 at 11:47 UTC |