On 05/26/00, "Greg Wardawy <[EMAIL PROTECTED]>" wrote:
> but I can't find my way to complete this task. From the following csv file
> I need to print just the lines for which the sum of the seventh element for
> this same fourth element is >= 3 (e.g.), the third element is in dopo.csv
> and the fifth element is not in nostock.csv:
> 3,1000000015,R518672,206,HAVCONSTRUCTION,17.99,1,05,17,00

just read in all three files, keep a running total
on the third and filter out the is/isn't in constraints,
then go back and print whatever passes the sum constraint:

# Assuming all files are opened ok
# And we remember to close them
while (<DOPO>) {
 chomp;
 s/,.*//;
 $dopo{$_}=1;
}

while (<STOCK>) {
 chomp;
 s/,.*//;
 $stock{$_}=1;
}

while (<ORD>) {
 my ($dopo, $key, $stock, $value) = (split /,/)[2,3,4,6];
 next unless $dopo{$dopo} and !$nostock{$stock}
 $totals{$key} += $value;
 # Save in memory? or open file again later?
 push (@ord_array, $_)
}

for (@ord_array) {
 my ($key) = (split /,/)[3];
 next unless $totals{$key} >= 3;
 print;
}

HTH,
Douglas Wilson

---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to