Ok, open your favorite text editor, type in this program and save the file as "fps.pl" in the same directory as "fps.csv":
#!perl -w
my $total = 0;
my $lines = 0;
my $infile = "fps.csv";
my $outfile = "out.txt";
# read $infile and process it
open (IN, "<", $infile) or die "Can't open $infile for reading: $!";
while (<IN>) {
next if /^\s*$/; # ignore blank lines or lines that have whitespaces only
chomp; # remove EOL character
$total += (split /[,:]/)[1]; # running total of the FPS value
$lines++; # increment the line number
}
close (IN) or die "Can't close $infile: $!";
# now write to $outfile
open (OUT, ">", $outfile) or die "Can't open $outfile for writing: $!";
print OUT $total/$lines; # average is the total of FPS values divided by linecount
close (OUT) or die "Can't close $outfile: $!";
The inline comments should be self-explanatory.
Once you are at the DOS prompt after saving the Perl program "fps.pl", the "type" command should show something like this:
C:\>
C:\>
C:\>type fps.pl
#!perl -w
my $total = 0;
my $lines = 0;
my $infile = "fps.csv";
my $outfile = "out.txt";
# read $infile and process it
open (IN, "<", $infile) or die "Can't open $infile for reading: $!";
while (<IN>) {
next if /^\s*$/; # ignore blank lines or lines that have whitespaces only
chomp; # remove EOL character
$total += (split /[,:]/)[1]; # running total of the FPS value
$lines++; # increment the line number
}
close (IN) or die "Can't close $infile: $!";
# now write to $outfile
open (OUT, ">", $outfile) or die "Can't open $outfile for writing: $!";
print OUT $total/$lines; # average is the total of FPS values divided by linecount
close (OUT) or die "Can't close $outfile: $!";
C:\>
C:\>
Now feed the Perl program to your perl interpreter like so:
C:\>
C:\>perl fps.pl
C:\>
C:\>
Note that no output is displayed in the DOS window. The control simply returns to the next prompt.
However, the output file called "out.txt" should've been created in the same directory as "fps.csv" and "fps.pl".
To display the contents of "out.txt", use the DOS "type" command:
C:\>
C:\>type out.txt
30.1827114285714
C:\>
C:\>
tyler_durden