aschroh has asked for the wisdom of the Perl Monks concerning the following question:
$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("E +rror reading /usr/local/download/chenny/invoice-raw1.txt -> $!"); flock(DATA, $LOCK_EX); # lock the INVOICE1 file open(CONVERTED,">>/usr/local/download/chenny/invoicedetail.txt") || &e +rror("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 op +ening invoicecheck for reading -> $!"); flock(KEY, $LOCK_EX); while(<DATA>){ ($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(<KEY>){ ($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,$quantityordere +d,$quantityshipped,$quantitybackordered,$c17,$c18,$replacementcost,$f +et,$recapordernumber,$recaporderlinenumber,$recapdealercustomer,$reca +pdealerinvoice,$comissioncode,$treaddepth,$percentageofwear,$releasen +umber,$pricechanged,$costchanged,$addlineitem,$spifamount,$mechanic,$ +c20,$itemdiscount,$serialnumber,$brandnumber,$brandcustomer,$contract +number,$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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to compare a field in 2 files and set a value if it matches?
by tall_man (Parson) on May 20, 2003 at 21:16 UTC | |
by aschroh (Novice) on May 20, 2003 at 23:34 UTC | |
by Anonymous Monk on Jul 17, 2003 at 09:25 UTC | |
|
Re: How to compare a field in 2 files and set a value if it matches?
by chromatic (Archbishop) on May 20, 2003 at 21:20 UTC | |
|
Re: How to compare a field in 2 files and set a value if it matches?
by pzbagel (Chaplain) on May 20, 2003 at 21:35 UTC | |
|
Re: How to compare a field in 2 files and set a value if it matches?
by benn (Vicar) on May 20, 2003 at 21:19 UTC | |
by aschroh (Novice) on May 20, 2003 at 22:03 UTC |