Ola,

I have the following data
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
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:
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
So I wrote this simple script:
#! 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";
Which produced this incorrect 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
I have spent sometime thinking about a solution for it, but the best I can produce is the above output.

Since coding problems like these are an absolute doddle for you guys, I wonder if someone can help me and show me how can I produce the required results efficiently and with minimal code?

Thanks for your help


In reply to searching 2 arrays by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.