egunnar has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w #use integer; my $file = 'test_data.dat'; open (IN,$file) or die "Can't open file - $file - $!"; my $data; print "Reading: [$file]\n"; my $val = 0; my @arr; while (<IN>){ /(?:\d+,){99}(\d+),/; $val += $1; #print "$1\n"; #@arr = split(',', $_); #$val = $arr[99]; #print "$val\n\n"; print STDERR "Working on: [$.]:[$val]\r" unless ($. % 100_000); } print STDERR "Final: [$val]\n"; exit;
#include "stdio.h" int main(){ char buf[100000], *ptr, *ptr2; FILE *fptr; int count = 0, i; long total = 0l; fptr = fopen("test_data.dat", "r"); if (!fptr){ printf ("Can't open test_data.dat\n"); exit(1); } while (fgets(buf,100000,fptr)){ /* printf("Read: [%s]\n", buf); */ ptr = buf; for (i = 0; i < 99; i++){ ptr++; ptr = index(ptr,','); /* printf("Read: [%d]:[%s]\n", i, ptr); */ } ptr++; ptr2 = index(ptr,','); *ptr2 = '\0'; total += atol(ptr); /* printf("Read: [%s][%ld]\n", ptr, total); */ count++; } printf ("Read %d records, total: [%ld]", count, total); }
|
|---|