in reply to Re^2: Advances SQL calculations in CSV file
in thread Advances SQL calculations in CSV file
my %stats; open MYFILE, "<data.txt" or die "Can not open file: $!"; chomp(my $heading = <MYFILE>); my @col = split /,/, $heading; while (my $line = <MYFILE>) { # build a hash for the input record chomp($line); my @rec = split /,/, $line; my %rec; @rec{@col} = @rec; # collect stats $stats{$rec{rec_id}}{BAL} += $rec{bal}; $stats{$rec{rec_id}}{NUM} ++; } # print the stats here for my $id (keys %rec) { if ($rec{$id}{NUM}) { print "$id => ", $rec{$id}{BAL}/$rec{$id}{NUM}, "\n" } } close MYFILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Advances SQL calculations in CSV file
by DrAxeman (Scribe) on Aug 31, 2005 at 19:52 UTC |