PERL BEGINNERS 33 SIMPLE QUESTION
Subject: Simple question
Date: Fri, 8 Aug 2003 07:09:24 -0600

From: demo@no-spam (Trevor Morrison)

Hi,

I am trying to compare two arrays to find common numbers in both. For the numbers that are not common to both, I want to write them to a file for my review. I have included the code below, but it is not working as intended.
I know that this is a real basic question, but I have been staring at this for hours and am not seeing it. I am assuming that there must me a module that will do this, but I have decided to reinvent the wheel!

TIA
Trevor
#!/usr/local/bin/perl
#============
# Main script #------------
use strict;
#use warnings;

#Use Perl's Database Interface (DBI) with the NySQL module to connect the Maverick database use DBI;
my %attr = (PrintError => 1, RaiseError => 1);
my $dbname='maverick';
my $dbuser='root';
my $dbpass='';
my $dbh=DBI->connect('DBI:mysql:database=maverick;host=localhost;port=3306',"$d buser","$dbpass", \%attr) || die "Unable to connect to database maverick on localhost: $DBI::errstr\n";

my $email = qw(c:\\maverick\\trevor_trial2.txt);
our @no-spam our @no-spam our $order;
our $stash;
our $carryover;
our $found = "true";
open(ORDER,$email) or die "Error opening \"$email\": $!\n";
my $n = 0;
my $sth =$dbh->prepare("SELECT order_number FROM miva_orders");
$sth->execute();

while (<ORDER>) {
if ($_=~ /Order\s+Number\s+:\s+(.*)$/i ) {
$orders[$n] = $1;
$n += 1;
#print $n;
}
}
foreach my $order(@no-spam {
#print "$order\n";
}
while (my $array_ref = $sth->fetchrow_arrayref) {
push @no-spam [ @no-spam ];
}

# Check to see if order numbers are equal and if not print them to a file for review open (CHECKER, ">c:\\maverick\\ordercheck.txt") || die $!;

STASH: foreach $order(@no-spam {

foreach my $stash (@no-spam {
if ($order == @no-spam
$found = "true";
#next STASH;
}
}
if ($found eq "false") {
print $order;
print CHECKER $order . "\n";
#$found == 0;
}

}
# Disconnnect from the database $sth->finish;
$dbh->disconnect;

close(CHECKER);


Date: Fri, 08 Aug 2003 13:04:12 -0400

Subject: Re: Simple question
From: dwall@no-spam (David K. Wall)
Trevor Morrison <demo@no-spam> wrote:

> I am trying to compare two arrays to find common numbers in both. For > the numbers that are not common to both, I want to write them to a file > for my review.

Check the FAQ:

perldoc -q "difference of two arrays"

How do I compute the difference of two arrays? How do I compute the intersection of two arrays?