my %G01totals = (
'01' => 0, '02' => 0, '03' => 0, '04' => 0, '05' => 0, '06' => 0, '07' => 0,
'08' => 0, '09' => 0, '10' => 0, '11' => 0, '12' => 0, '13' => 0, '14' => 0,
'15' => 0, '16' => 0, '17' => 0, '18' => 0, '19' => 0, '20' => 0, '21' => 0,
);
my %G02totals = (
'01' => 0, '02' => 0, '03' => 0, '04' => 0, '05' => 0, '06' => 0, '07' => 0,
'08' => 0, '09' => 0, '10' => 0, '11' => 0, '12' => 0, '13' => 0, '14' => 0,
'15' => 0, '16' => 0, '17' => 0, '18' => 0, '19' => 0, '20' => 0, '21' => 0,
);
my %G03totals = (
'01' => 0, '02' => 0, '03' => 0, '04' => 0, '05' => 0, '06' => 0, '07' => 0,
'08' => 0, '09' => 0, '10' => 0, '11' => 0, '12' => 0, '13' => 0, '14' => 0,
'15' => 0, '16' => 0, '17' => 0, '18' => 0, '19' => 0, '20' => 0, '21' => 0,
);
####
while (my $line = <$file>) {
chomp ($line);
my ($in_game, $in_three, $in_two, $in_one) = split (',', $line);
if ($in_game eq 'G01') {
$G01totals{$in_three} += 3;
$G01totals{$in_two} += 2;
$G01totals{$in_one} += 1;
}
if ($in_game eq 'G02') {
$G02totals{$in_three} += 3;
$G02totals{$in_two} += 2;
$G02totals{$in_one} += 1;
}
if ($in_game eq 'G03') {
$G03totals{$in_three} += 3;
$G03totals{$in_two} += 2;
$G03totals{$in_one} += 1;
}
}
####
while (my $line = <$file>) {
chomp ($line);
my ($in_game, $three, $two, $one) = split (',', $line);
$totals{$in_game}{$three} += 3;
$totals{$in_game}{$two} += 2;
$totals{$in_game}{$one} += 1;
}
####
%totals = %G01totals;
create_tables ($print_heading, $game_index, %totals);
####
for (my $i=1;$i<3;$i++) {
$print_heading = 1;
$game_index = $i;
create_tables ($print_heading, $game_index, %totals);
}
####
sub create_tables {
my ($heading_flag, $game_no, %totals) = @_;
if( %totals) {
open( $out_file, '>', $obtain_321_file )
or die "G1 Open output file $obtain_321_file failed $!";
foreach $key (sort sortvalue (keys(%totals))) {
if (! $totals{$key} == 0) {
print ($out_file "$totals{$key},$players{$key}\n");
}
}
close ( $out_file );
calculate_overall_results();
close ( $out_file );
}
####
sub create_tables {
my ($heading_flag, $game_no, %totals) = @_;
if( %totals) {
open( $out_file, '>', $obtain_321_file )
or die "G1 Open output file $obtain_321_file failed $!";
foreach $game_no (sort keys %totals) {
foreach my $key (sort keys %{$totals{$game_no}}) {
if (! $totals{$game_no} == 0) {
print ($out_file "$totals{$game_no}{$key},$players{$key}\n");
}
}
}
close ( $out_file );
calculate_overall_results();
close ( $out_file );
}