Hello,
The following is based on the first example in Programming Perl,
and have a question about some of the syntax
(and or why it was doen this way)
$grades{$student} .= $grade . " ";
Why not $grades{$student} = $grade;
Why the concatenation and the extra space?
$average = sprintf ("%3d", ($total / $scores));
I want to allow for values like 2.5, 11.5, 2, 22 ...
Finally am I using the Format correctly (assigning $~ )
Thanks
Dave
---Begin--
#!/usr/bin/perl
open (GRADES, "grades.txt") || die "Can't open grades $!\n";
while ($line=<GRADES>){
($student,$grade)= split(" ",$line);
$grades{$student} .= $grade . " ";
}
local $~ = grades_header;
write;
local $~ = grades_format;
foreach $student (sort keys %grades){
$total = 0;
@grades = split (" ",$grades{$student});
foreach $grade (@grades){
$total+= $grade;
$scores++;
}
$average = sprintf ("%4d", ($total / $scores));
write;
# print "$student: $grades{$student}\tAverage: $average\n";
}
format grades_header =
Student Score Average
-----------------------------
.
format grades_format =
@<<<<<<<<<< @<< @<<<<
$student,$grades{$student},$average
.
--------------------------------------------
Looking for Web Talent, You found it!
portfolio: www.coraconnection.com/web/
email: [EMAIL PROTECTED]
tel/fax: (860) 231-9988
--------------------------------------------