I'm sure it will be obvious by my post, but my knowledge of Perl, and programming for that matter, is limited so please be gentle.
I am trying to read in a directory of files, sort the files into other directories based on their contents
(one particular field actually) and then have the file not exist in the original directory.
Here is the code I came up with but it seems a little barbaric and like it could be better, there are some environment
variables that I don't think will affect the purpose. Please let me know if any other details are needed.
use strict;
use File::Copy;
use Cwd;
#---------Split
my $directory = "$ENV{FTP_PRODUCTION}\\CDSEXP\\GOL";
my @filenames = glob ("$directory\\*.tpe");
my $start1 = '0';
my $len1 = '8';
my $start2 = '128';
my $len2 = '5';
my $newloc1 = $ENV{FTP_PRODUCTION} . '\CDSEXP\GOL\refund_proceed';
my $newloc2 = $ENV{FTP_PRODUCTION} . '\CDSEXP\GOL\other';
my $newloc3 = $ENV{FTP_PRODUCTION} . '\CDSEXP\GOL';
foreach my $filename (@filenames){
open (FILEIN, $filename) or die "Unable to open in file.";
while (defined(my $record = <FILEIN>)) {
my $rec = substr($record, $start1, $len1);
my $type = substr($record, $start2, $len2);
if ($rec eq "10025900"){
if ($type eq "MANDV"){
close FILEIN;
move ("$filename", "$newloc1") or die "Unable to refund_proceed";
}else{
close FILEIN;
move ("$filename", "$newloc2") or die "Unable to other";
}
}else{
}
}
}#End of the 4 each file
I am trying to read in a directory of files, sort the files into other directories based on their contents
(one particular field actually) and then have the file not exist in the original directory.
Here is the code I came up with but it seems a little barbaric and like it could be better, there are some environment
variables that I don't think will affect the purpose. Please let me know if any other details are needed.
use strict;
use File::Copy;
use Cwd;
#---------Split
my $directory = "$ENV{FTP_PRODUCTION}\\CDSEXP\\GOL";
my @filenames = glob ("$directory\\*.tpe");
my $start1 = '0';
my $len1 = '8';
my $start2 = '128';
my $len2 = '5';
my $newloc1 = $ENV{FTP_PRODUCTION} . '\CDSEXP\GOL\refund_proceed';
my $newloc2 = $ENV{FTP_PRODUCTION} . '\CDSEXP\GOL\other';
my $newloc3 = $ENV{FTP_PRODUCTION} . '\CDSEXP\GOL';
foreach my $filename (@filenames){
open (FILEIN, $filename) or die "Unable to open in file.";
while (defined(my $record = <FILEIN>)) {
my $rec = substr($record, $start1, $len1);
my $type = substr($record, $start2, $len2);
if ($rec eq "10025900"){
if ($type eq "MANDV"){
close FILEIN;
move ("$filename", "$newloc1") or die "Unable to refund_proceed";
}else{
close FILEIN;
move ("$filename", "$newloc2") or die "Unable to other";
}
}else{
}
}
}#End of the 4 each file