Hi there,
I would be grateful for some help on the following:
I have to query the database and create a file with the order numbers, which I have done. I then need to read the contents of a number of different txt files in a directory and match the order number from my list in these txt files. If there is a match I need to move the file. However, my script does not seem to work when I try to parse the order number from the file as the match expression, it works when I type a known order number in the match expression.
My scripts is below, any help would be appreciated...thanks
use DBI;
use MIME::Lite;
# Connect to the Database
my $db = DBI->connect("dbi:Oracle

ATABASE", "username", "password", { AutoCommit => 0 } );
check connect to DB
$db or (print <<EOD
Error: Can't connect to database
EOD
and die $DBI::errstr);
print "connected.\n";
# SQL Query to extract data
my $O4K_Clients = qq{select distinct mo.orderno
from monitororder mo, deliveryaddress da
where mo.DELIVERYADDRESSID = da.DELIVERYADDRESSID
and mo.ORDERNAME like '%/26%'
};
my $sth = $db->prepare ($O4K_Clients);
$sth->execute();
my $log = "\\\\pgitdept06\\c\$\\data\\test\\O4K_Portal_Names .txt";
open OUTPUT, "> $log";
while (($row) = $sth->fetchrow_array) {
chomp $row;
print OUTPUT "$row\n";
}
close OUTPUT;
$sth->finish();
$db->disconnect();
$directory = "\\\\pgitdept06\\c\$\\data\\test\\";
open(DAT, $log) || die("Could not open file!");
@raw_data=<DAT>;
close(DAT);
foreach $O4K_Portal_Clients(@raw_data)
{
print "$O4K_Portal_Clients\n";
opendir(DIR1, "$directory");
@files1 = readdir(DIR1);
$arrlength1 = @files1;
closedir(DIR1);
my $xmlcount = 0;
for ($x = 0; $x <= $arrlength1; $x++)
{
$path = "$directory@files1[$x]";
print "$path\n\n";
if ( @files1[$x] =~ m/.xml/ )
{
open(DAT, $path) || die("Could not open file!");
@xml_file=<DAT>;
foreach $line (@xml_file)
{
if ($line=~ m/($O4K_Portal_Clients)/)
{
close(DAT);
print "@files1[$x] is A O4K xml\n\n";
move("$directory@files1[$x]","$directorymove@files1[$x]") or die ("Error in moving XML's");
}
else
{
print "@files1[$x] is NOT AN O4K xml\n\n";
}
}
}
$xmlcount++;
}
}