Thanks for the reply. I think I got past that issue. I have two test files. One with all Monday dates, and one with other dates. I am expecting these files to be moved to the corresponding directories. The files are being moved as expected, for some reason I am getting another error: "Could not move the file /opt/manu/manu71/transport/natt1/order_temp/ord.20060221230012. Move failed: A file or directory in the path name does not exist. at test.pl line 109, <FILEH> line 4"
The other issue is that the code is supposed to print every order number and order date, and the order day (Mon..Fri). On the second test file, that has only Monday dates, only the first two lines are printed, when I am expecting 4. Any clues?
use strict;
use File::Copy;
use Time::Local;
use lib "/opt/perl/lib/site_perl/5.6.1/Mail";
use Mail::Sender;
my $instance = "natt1";
my $instance_root = "/opt/manu/manu71/transport/$instance";
my $goodordpath = "$instance_root/order_good";
my $badordpath = "$instance_root/order_bad";
my $allmonday = 0;
my $starttime = localtime;
print "\n\n*** Starttime = $starttime ***\n\n";
if (-d "$instance_root/order_temp") {
my $where = "$instance_root/order_temp";
print "Directory $where exists. Directory check was successful.\n\n";
# find the number of files we are to process
my @count = (<$instance_root/order_temp/ord.*>);
my $plural = (scalar(@count = (<$instance_root/order_temp/ord.*>)) == 1) ? "" : "s";
print "Processing ", scalar @count, " order file$plural.\n";
foreach my $orderfile (<$instance_root/order_temp/ord.*> ) {
print "\nProcessing Order File: $orderfile\n";
open (FILEH, $orderfile) or die "Could not open order file: $orderfile : $!\n";
while (my $line = <FILEH>) # loop as long as there are records in the file
{
my $ordertype = substr($line, 0, 2); # used to find the order header
if ($ordertype eq "HM") # only look at the dates on the header records
{
my $ordernum = substr($line, 3, 7);
my $date_str = substr($line, 64, 8);
my ($year, $month, $day) = $date_str =~ m/(\d{4})(\d{2})(\d{2})/;
my $time = timelocal("", "", "", $day, $month-1, $year); # For $month: Jan = 0, Feb = 1, etc.
if ((localtime($time))[6] == 1 ) # Monday
{
print " Order Number = $ordernum Order Date = $date_str is a Monday\n";
# We have found a date that is a Monday. We need to keep looking at the
# rest of the dates to see if the rest of the dates are Mondays
$allmonday = 1;
next; # move onto the next record and look at it
}
else
{
$allmonday = 0;
print " Order Number = $ordernum Order Date = $date_str is not a Monday. This file is OK to move and process.\n";
# We have found a date that is not a Monday. This file is OK. We need to move it to be processed
close FILEH;
move("$orderfile", $goodordpath) or die "Could not move the file $orderfile. Move failed: $!";
last; # bail out of the loop if date is not Monday
}
}
if (scalar $allmonday) {
move("$orderfile", $badordpath) or die "\nCould not move the file $orderfile. Move failed: $!";
$allmonday = 0;
}
}
close FILEH;
}
} else {
my $where = "$instance_root/order_temp";
print "Directory $where does not exist...now exiting\n\n";
}
my $endtime = localtime;
print "\n*** Endtime = $endtime ***\n\n";