Ok here we go: I don't know where the +'s are coming from but they are not in the code...the red pluses that is...
#!/usr/local/bin/perl
#+---------------------------------------------+
#| Configuration Options |
#+---------------------------------------------+
$dirname = "C:\\Working\\";
$mastertemp = "C:\\master.txt";
$dupefile = "C:\\dupes.txt";
$newmaster = "C:\\newmaster.txt";
main();
sub main{
dirlist();
extract_data();
output_results();
}
sub dirlist{
+ # Pull Directory Listing
opendir(DIR, $dirname) or die "can't opendir $dirname: $!";
+ # open the directory
while (defined($file = readdir(DIR))) {
+ # read the directory
next if $file =~ /^\.\.?$/;
push(@dirlisting, $file); #
+ put dirlist in @dirlisting
}
}
sub extract_data {
+ # Get list of archived files
%lines;
%dupez;
foreach (@dirlisting){
+ #
$filename1 = $_;
open(INPUTFILE, "$dirname" . "$filename1");
open(MASTERTEMP, ">>$mastertemp");
open(DUPES, ">>$dupefile");
while (<INPUTFILE>) {
$custID = substr($_,0,9);
$ccn = substr($_,22,16);
$expy = substr($_,44,4);
$type = substr($_,50,3);
$amount = substr($_,58,6);
# $amount =~ s/^\s+//;
if (($custID lt 0) || ($custID eq "Name ")){
}else{
dupeczech();
print MASTERTEMP "$custID"." "."$ccn"." "."$e
+xpy"." "."$type"." "."$amount\n";
}
}
close(INPUTFILE);
close(MASTERTEMP);
close(DUPES);
}
}
sub dupeczech {
$lines{$ccn}++; #add one to the value if it hasn't been def
+ined yet it sets it equal to 1
if($lines{$ccn} == 2){ #been seen before so add to dupes list
push @dupes, $ccn;
# print "$ccn $custID $lines{$ccn}\n";
# print DUPES "$custID"." "."$ccn"." "."$expy\n";
}
}
sub output_results {
open(MASTERTEMP, "$mastertemp");
open(DUPES, ">>$dupefile");
open(NEWMASTER, ">>$newmaster");
while (<MASTERTEMP>) {
$custID = substr($_,0,9);
$ccn = substr($_,22,16);
$expy = substr($_,44,4);
$type = substr($_,50,3);
$amount = substr($_,58,6);
foreach (@dupes){
if ($ccn eq $_) {
print DUPES "$custID"." "."$ccn"." "."$ex
+py"." "."$type"." "."$amount\n";
$dupez{$ccn}++;
}
}
if (!$dupez{$ccn}){
print NEWMASTER "$custID"." "."$ccn"." "."$ex
+py"." "."$type"." "."$amount\n";
}
}
close(NEWMASTER);
close(MASTERTEMP);
close(DUPES);
}
|