my %total_for;
####
my $operator = 'Nicole';
$total_for{$operator} = 123; # total for Nicole is 123
$total_for{$operator} += 45; # increase Nicole's total by 45.
####
foreach my $operator ( sort keys %total_for ) {
print "Total for $operator: $total_for{$operator}\n";
}
####
open(LOG, $file) or die "Can't read '$file': $!";
####
while () {
@tmpwords = split;
# etc.
}
####
foreach my $blah ( @array ) {
# use $blah instead of $_ for things
}
####
use strict;
use warnings;
my $file = 'msgcount.txt';
open my $fh, '<', $file
or die "Can't read '$file': $!";
my %total_for;
while ( <$fh> ) {
my $line = $_;
chomp;
s{ \A \d\d / \d\d / \d{4} \s+ }{}xms
or die "line does not match: $line";
my ( $name, $numb ) = m{ \A ( .+ ) \s+ ( \d+ ) \s* \z }xms;
if ( ! $name ) {
die "line does not match: $line";
}
$total_for{ $name } += $numb;
}
close $fh or die "Failed to close: $!";
foreach my $operator ( sort keys %total_for ) {
print "Total for '$operator': $total_for{$operator}\n";
}