open (my $INFILE_1, '<', 'name_o_file.txt') ||
croak "Cannot open input file: $!\n";
####
open(my $CDA1, '<', 'cda1_raw.txt') ||
croak "Cannot open input file 1: $!\n";
open(my $CDA2, '<', 'cda2_raw.txt') ||
croak "Cannot open input file 2: $!\n";
report_one($CDA1, 'cda1_boffle.txt');
report_one($CDA2, 'cda2_boffle.txt');
report_two($CDA1, $CDA2, $dbh);
close $CDA1;
close $CDA2;
####
open(my $CDA1, '<', 'cda1_raw.txt') ||
croak "Cannot open input file 1: $!\n";
open(my $CDA2, '<', 'cda2_raw.txt') ||
croak "Cannot open input file 2: $!\n";
report_one($CDA1, 'cda1_boffle.txt');
report_one($CDA2, 'cda2_boffle.txt');
open(my $CDA3, '<', 'cda1_raw.txt') ||
croak "Cannot open input file: $!\n";
open(my $CDA4, '<', 'cda2_raw.txt') ||
croak "Cannot open input file: $!\n";
report_three ($CDA3, $CDA4, $dbh);
close $CDA1;
close $CDA2;
close $CDA3;
close $CDA4;
####
sub report_one {
my ($input_handle, $output_name) = @_;
open(my $OUT, '>', "$output_name") ||
croak "Cannot open output file: $!\n";
my $current_host = "";
my %host_counts;
my @rows = (<$input_handle>);
foreach ( @rows ) {
my ($date, $time, $host, $bytes, $bytes_sec, $server) = split /\t/;
if ( ( $bytes < 1000000 ) || ( $bytes == $bytes_sec ) ) {
next;
}
if ( $host eq $current_host ) {
$host_counts{$host}{bytes} += $bytes;
$host_counts{$host}{speed} += $bytes_sec;
$host_counts{$host}{count}++;
} else {
$host_counts{$host}{bytes} = $bytes;
$host_counts{$host}{speed} = $bytes_sec;
$host_counts{$host}{count} = 1;
}
$current_host = $host;
}
foreach my $heauxst ( keys %host_counts ){
my $avg_speed = int( $host_counts{$heauxst}{speed} / $host_counts{$heauxst}{count} );
print $OUT "$heauxst\t$host_counts{$heauxst}{bytes}\t$avg_speed\n";
}
close $OUT;
return;
}