Commit 91bd6e81 authored by Robert Ricci's avatar Robert Ricci

Simple script to add up a scorefile

parent a90f5674
#!/usr/bin/perl -w
my $SCOREFILE = "score.txt";
open(SCORE,"<$SCOREFILE") or die "Unable to open $SCOREFILE: $!\n";
my @scorefile = <SCORE>;
chomp @scorefile;
close(SCORE);
my $total = 0;
my $total_possible = 0;
my $found_totalline;
foreach my $line (@scorefile) {
if ($line =~ /^\s*(\d+|XX)(\s*\/\s*(\d+)\s*)?/) {
my ($score, $possible) = ($1, $3);
if ($score eq "XX") {
die "Score not filled on line: $line\n";
} else {
$total += $score;
}
if ($possible) {
$total_possible += $possible;
}
} elsif ($line =~ /^\s*Total:\s*(XX|\d+)?\s*\/\s*(YY|\d+)?/) {
$line = "Total: $total / $total_possible\n";
print $line;
}
}
if ($total_possible == 0) {
die "Error: Didn't find a non-zero total possible score\n";
}
if (!$found_totalline) {
my $line = "Total: $total / $total_possible";
push @scorefile, $line;
print $line;
}
open(SCORE,">$SCOREFILE") or die "Unable to write to $SCOREFILE: $!\n";
print SCORE join("\n",@scorefile);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment