Thanks for your help. I'm so close, but something is not working. I am trying to debug the following, but it seems that although both the @file contain the @report strings, I am not getting a match. Is it possible when I load the text file into @file array, that the elements are not compared as strings? Frusterating!!!!! The contents of the @file looks like this:
sqltable_mike table loaded successfully with 282873
sarak_mike table loaded successfully with 282873 records
sticks table loaded successfully with 282873 records.
hello table loaded successfully with 282873 records.
All I need it to do is match all @report contents with the internal @file. What am I doing wrong. Your assistance is greatly appreciated. <CODE> use strict;
my @compare=();
my $file='d:\mms_tableload.txt';
my @file="";
open(FILE,"<$file");
@file = <FILE>;
close(FILE);
my @report = qw(sqltable_mike sarak_mike );
my @compare = ( @report, qw (@file ));
# off by 0
print '@file was off by '
. simple_compare(\@report,\@compare)
. " elements\n";
# still 0, that elem wasn't in @report
pop @file;
print '@file was off by '
. simple_compare(\@report,\@compare)
. " elements\n";
# off by 1, that one was
shift @file;
print '@file was off by '
. simple_compare(\@report,\@file)
. " elements\n";
# returns number of elements in A that aren't in B
sub simple_compare {
my ($A,$B) = @_;
# build lookup table
my %seen = map { $_ => 1 } @$B;
# find those in A that aren't in B
my @aonly;
foreach my $item (@$A) {
push @aonly,$item unless ($seen{$item});
}
return scalar @aonly;
}
<CODE>

In reply to Re: (jeffa) 2Re: comparing two arrays by jdelmedi
in thread comparing two arrays by jdelmedi

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.