in reply to Re: Programming Perl 3rd ed. Chapter 1
in thread Programming Perl 3rd ed. Chapter 1

What you did will help prevent typos, but now you're using lexical variables as globals which is not a good idea. You should declare lexicals so they stay inside the relevant scope. Also got rid of double quotes where interpolation is not needed, and lost any unneccessary parenthesis, and specify the mode for open:
open my $fh, '<', 'grades' or die "Can't open grades: $!\n"; while (my $line = <$fh>) { my ($student, $grade) = split ' ', $line; $grades{$student} .= $grade . ' '; } foreach my $student (sort keys %grades) { my ($scores, $total) = (0, 0); my @grades = split ' ', $grades{$student}; foreach my $grade (@grades) { $total += $grade; $scores++; } my $average = $total / $scores; print "$student: $grades{$student}\tAverage: $average\n"; }