I am running a simple script that is reading through a text file and adding up 
floating point numbers from each line.
At the 2165 line the number goes wrong. All the numbers are money \d+.\d\d
all numbers in the hundreds to thousands.

I have removed lines thinking maybe something was screwy with the data. If i 
erase the line its the next on.
If I am manually insert a line with a number it becomes that one.


Code below.... (I know its ugly but its one of those 1 time scripts that is  
built as you go to massage the data) The only part that is relevent to this 
issue is the total counter. $total.


here is a sample of the data....


585-00-00       Other Purchases                           SUPE01     1031776           
             
76.38
585-00-00       Other Purchases                           SURE00     00062967          
            
228.00
585-00-00       Other Purchases                           SURE00     00063067          
            
212.64
585-00-00       Other Purchases                           SWED00     066804            
            
171.00
585-00-00       Other Purchases                           SWED00     067034            
            
219.75
585-00-00       Other Purchases                           SWED00     067140            
            
143.00
585-00-00       Other Purchases                           SWED00     067187            
            
178.50
585-00-00       Other Purchases                           SWED00     067297            
            
221.50
585-00-00       Other Purchases                           SWED00     067408            
             
23.00
585-00-00       Other Purchases                           SWED00     067411            
             
92.00
585-00-00       Other Purchases                           SWED00     067564            
            
106.00
585-00-00       Other Purchases                           SWED00     067677            
            
111.00
585-00-00       Other Purchases                           SWED00     067830            
            
373.50
585-00-00       Other Purchases                           TECH02     10406             
            
680.16
585-00-00       Other Purchases                           TECH02     10414             
            
565.04
585-00-00       Other Purchases                           TECH02     10479             
            
687.96
585-00-00       Other Purchases                           TECH02     10480             
            
679.08


Any ideas?

Paul

Code
--------
#!/usr/bin/perl

use strict;
use warnings;
my %vendors;
my $total;
my $credits;
my $linecount;
while ( <> ) {
  chomp;
  next unless ( /^\d\d\d-\d\d-\d\d/ ) ;
  if ( /([\w\&]{4}\d\d)\s+/){
    my $vendor = $1;
    my @record = split /\s+/, $';
    $record[1]=~ s/,//g;
    if ( length( $_) == 121 ) {
      $credits += $record[1];
      $record[1] *= -1;
    }

    $vendors{$vendor} += $record[1];
    $total += $record[1];
    $linecount++;
    print "$linecount:$total\n";
    if ( $total =~ /\.\d\d9/ ){
      print  "$_\n";
      print "$total\n";
      die;
    }
  } else { 

  }
}

open ( LONG, "<long.txt" );
my %long;
my $longtotal;
while ( <LONG> ) {
  chomp;
  if  ( /^\s{66}Vendor/ ) {
    my $record = $';
    my @record = split /\s+/, $record;

    $_ =~ s/^\s+|\s+$//g foreach @record;
    $record[4] =~ s/,//g;
    $long{ $record[1] } = $record[4];
    $longtotal += $record[4];
  }
}

foreach my $vendor( sort keys %long ){
   printf ( "%-10s %13f\n", $vendor, $long{$vendor} );
 }
# die;

foreach my $vendor ( sort keys %vendors ) {
  printf ( "%-10s %13f\n", $vendor, $vendors{$vendor} );
}
print "shorttotal:" . ($total - 3014.73) ."\n";
print "shorttotal:$total\n";
print "credits:" . ($credits + 1636519.35 + 3014.73) . "\n";
print "longtotal:$longtotal\n";


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to