#!/usr/bin/perl use warnings; use strict; use lib "/opt/perl/lib/site_perl/5.6.1/Mail"; use Mail::Sender; use File::Basename 'basename'; use POSIX 'mktime'; my $instance = 'natt1'; my $instance_root = "/opt/manu/manu71/transport/$instance"; my $goodordpath = "$instance_root/order_good"; my $badordpath = "$instance_root/order_bad"; my $where = "$instance_root/order_temp"; print "\n\n*** Starttime = " . localtime . " ***\n\n"; -d $where or die "Directory $where does not exist...now exiting\n\n"; print "Directory $where exists. Directory check was successful.\n\n"; # find the number of files we are to process # if there are no files to process, bail @ARGV = <$where/ord.*> or die "\nThere are no files to process. Now exiting.\n"; print 'Processing ' . @ARGV . ' order file', @ARGV == 1 ? '' : 's', ".\n"; my ( $ordertype, $ordernum, $date_str, $time ); while ( <> ) { print "\nProcessing Order File: $ARG\n" if $. == 1; if ( /^HM(.{7})/ ) { $ordernum = $1; $date_str = substr $line, 64, 8; my ( $year, $month, $day ) = $date_str =~ /(\d{4})(\d{2})(\d{2})/; $time = mktime( 0, 0, 12, $day, $month - 1, $year - 1900 ); # For $month: Jan = 0, Feb = 1, etc. } if ( ( localtime $time )[ 6 ] != 1 ) { print " Order Number = $ordernum Order Date = $date_str is not a Monday. This file is OK to move and process.\n"; my $file = basename $ARGV; # save the file name before closing it! close ARGV; # close the file before moving it! rename "$where/$file", "$goodordpath/$file" or die "Could not move the file $file. Move failed: $!"; next; } if ( eof ) { print " Order Number = $ordernum has order dates that are all Mondays. This is a bad order file and is being moved to $badordpath\n"; my $file = basename $ARGV; # save the file name before closing it! close ARGV; # close the file before moving it! rename "$where/$file", "$badordpath/$file" or die "\nCould not move the file $file. Move failed: $!"; } } print "\n*** Endtime = " . localtime . " ***\n\n";