----- Original Message -----
From: Trevor Morrison <[EMAIL PROTECTED]>
Date: Friday, August 8, 2003 9:09 am
Subject: Simple question

> Hi,

Hello
> 
> 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!
> 
I think the problem is where you compare the elements, by the way there are beter ways 
of going about comparing, such as grep for example. This would also be much beter done 
with hash's. I am sure someone fro mthe list will showe you how its dont atleast oen 
fo those ways.
> 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',"$dbuser","$dbpass", 
> >\%attr) || die   "Unable to connect to database maverick on
> localhost: $DBI::errstr\n";
> 
> 
> my $email = qw(c:\\maverick\\trevor_trial2.txt);
> our @orders;
> our @stash;
> 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(@orders) {
>       #print  "$order\n";
>       }
> while (my $array_ref = $sth->fetchrow_arrayref) {
>               push @stash, [ @$array_ref ];
>               }
> 
> # 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(@orders) {
> 
>                                                       foreach  my 
> $stash (@stash) {
>                                                                
>       if ($order == @$stash)
# This should probebly be 
                if ($order == $stash) 
> 
>                                                                   
>                              $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);
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to