$LOCK_EX = 2; $LOCK_UN = 8; # open the Vendor file use Date::Calc qw/Add_Delta_Days/; open(DATA,"/usr/local/download/chenny/goodsold-raw1.txt") || &error("Error reading /usr/local/download/chenny/invoice-raw1.txt -> $!"); flock(DATA, $LOCK_EX); # lock the INVOICE1 file open(CONVERTED,">>/usr/local/download/chenny/invoicedetail.txt") || &error("Error opening /usr/local/download/chenny/invoicedetail.txt -> $!"); flock(CONVERTED, $LOCK_EX); # lock the CONVERTED file open(KEY,"/usr/local/download/chenny/invoicecheck") ||&error("Error opening invoicecheck for reading -> $!"); flock(KEY, $LOCK_EX); while(){ ($c1,$c2,$c3,$c4,$c5,$c6,$c7,$c8,$c9,$c10,$c11,$c12,$c13,$c14,$c15,$c16,$c17,$c18,$c19,$c20,$c21,$c22,$c23,$c24,$c25,$c26,$c27,$c28,$c29,$c30,$c31,$c32,$c33,$c34,$c35,$c36) = split(/ /); $flag = 0; while(){ ($s1,$s2) = split(/,/); if (($s1) eq ($c5)) { $custnmbr = $s2; $flag = 1; print $s1; print $custnmbr; } }; if ($flag == 1 ) { my $delta = $c2; my ($year,$month,$day) = Add_Delta_Days(1800,12,28,$delta); $date = sprintf("%4d%02d%02d", $year, $month, $day); print CONVERTED ("$c1,$invoicecount,$custnumbr,$c2,$c8,$store,$productlocation,$c9,$c11,$productvendor,$c15,$quantityordered,$quantityshipped,$quantitybackordered,$c17,$c18,$replacementcost,$fet,$recapordernumber,$recaporderlinenumber,$recapdealercustomer,$recapdealerinvoice,$comissioncode,$treaddepth,$percentageofwear,$releasenumber,$pricechanged,$costchanged,$addlineitem,$spifamount,$mechanic,$c20,$itemdiscount,$serialnumber,$brandnumber,$brandcustomer,$contractnumber,$claimnumber,$tireposition,$adjustment,$productexempt,$mapcode,$casingpurchase,$message,$linemsgassoc\n"); } }; flock(DATA, $LOCK_UN); close(DATA); flock(CONVERTED, $LOCK_UN); close(CONVERTED); flock(INVOICE, $LOCK_UN); close(INVOICE); flock(KEY, $LOCK_UN); close(KEY);