H
hiabhijeet
I am trying to execute the following sample program on WINDOWS but its not executing as expected. Its only reading the first line from the file and displaying it. Its not reading the rest of the lines -
open(GRADES, "grades") or die "Can't open grades: $!\n";
while(defined($line = <GRADES>)) {
print "[1] - $line\n";
($student, $grade) = split(" ", $line);
$grades{$student} .= $grade . " ";
print "[2] - $student\t$grade\n";
}
foreach $student (sort keys %grades) {
print "[3] - $student\n";
$scores = 0;
$total = 0;
@grades = split(" ", $grades{$student});
foreach $grade (@grades) {
$total += $grade;
$scores++;
}
$average = $total / $scores;
print "$student: $grades{$student}\tAverage: $average\n";
}
Please note - "grades" is a file that contains below data -
Noël 25
Ben 76
Clementine 49
Norm 66
Chris 92
Doug 42
Carol 25
Ben 12
Clementine 0
Norm 66
open(GRADES, "grades") or die "Can't open grades: $!\n";
while(defined($line = <GRADES>)) {
print "[1] - $line\n";
($student, $grade) = split(" ", $line);
$grades{$student} .= $grade . " ";
print "[2] - $student\t$grade\n";
}
foreach $student (sort keys %grades) {
print "[3] - $student\n";
$scores = 0;
$total = 0;
@grades = split(" ", $grades{$student});
foreach $grade (@grades) {
$total += $grade;
$scores++;
}
$average = $total / $scores;
print "$student: $grades{$student}\tAverage: $average\n";
}
Please note - "grades" is a file that contains below data -
Noël 25
Ben 76
Clementine 49
Norm 66
Chris 92
Doug 42
Carol 25
Ben 12
Clementine 0
Norm 66