#!/opt/ActivePerl/bin/perl
use strict;

package main;

my %hash = ();
my @files = ("srb1_data.csv","srb1_data1.csv","srb2_data.csv","srb2_data2.csv","srb3_data.csv","srb3_data2.csv","srb4_data1.csv","srb4_data2.csv","srb4_data3.csv","srb5_data1.csv","srb5_data2.csv","srb5_data3.csv","srb6_data.csv","srb6_data2.csv");

foreach my $file (@files) {
    # open the file
    open (my $fh, "<", $file) or die "Can't open the file $file: ";
    
    while (my $line =<$fh>)
    {
	chomp ($line);
	my($key, $number) = split(",", $line); # split on the comma
	$hash{$key} = $hash{$key} + $number;
    }
}

# Build the output
open OUT, ">SummaryFile.csv" or die $!;
foreach my $key (sort keys %hash )  {
    print OUT "$key,$hash{$key}\n"; # comma delimited
}

