On 05/27/00, "Greg Wardawy <[EMAIL PROTECTED]>" wrote:
> Douglas,
> Thank you very much for your quick reply. I can see I wasn't clear. I've
> got the same result but not in such a readable, professional way as yours.
> But that's still not what I need. I have to print all the lines for which
> the highest sum of the seventh element for the same fourth element is >= 3
> (e.g.) (and the third element is in dopo.csv and the fifth element is not
> in nostock.csv). So from:
> 3,1,R518672,206,HAVCONSTRUCTION,17.99,1,05,17,00
> 3,1,R518672,305,HAVCASTLE,17.99,1,05,17,00
> 3,1,R518672,305,HAVRADIORACERS,17.99,1,05,17,00
> 3,1,R518672,305,STRHOLISTIC,16.29,1,05,17,00
> 3,1,R518672,305,TLCBARBIESTORY,13.49,1,05,17,00
> I have to get:
> 3,1,R518672,305,HAVCASTLE,17.99,1,05,17,00              # not printed  -
> $totals =1;
> 3,1,R518672,305,HAVRADIORACERS,17.99,1,05,17,00         # not printed -
> $totals =2;
> 3,1,R518672,305,STRHOLISTIC,16.29,1,05,17,00            # printed - $totals
> =3;
> 3,1,R518672,305,TLCBARBIESTORY,13.49,1,05,17,00         # printed - $totals
> = 4;

I think I get it now. As soon as the totals hit 3 for a key,
you want to print that line and all following lines. The next
question is, do you want to include the totals from lines that
are not in dopo or in nostock. That's easy to deal with, though.
Throw out the last loop, and change the next to last loop from
this:

> >>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, $_)
> >>}

to this:
while (<ORD>) {
 my ($dopo, $key, $stock, $value) = (split /,/)[2,3,4,6];
 next unless $dopo{$dopo} and !$nostock{$stock}
 $totals{$key} += $value;
 print if $totals{$key} >= 3;
}

If you want to include the totals from lines not printed due
to the 'next unless' line, just move it after the '+=' line.

Of course in the previous posts, we were assuming that the
dopo and nostock values were the first value on the line in
their comma delimited files.

Is that what you wanted?
Good Luck,
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