yabba has asked for the wisdom of the Perl Monks concerning the following question:
The pa5c.dat file contains:use strict; my @data; my $avg; my $dev; my $std; my $tmp; my $grade; my $line; open(IN, "pa5c.dat") || die ("Can't open file $!\n"); while($line = <IN>){ chomp ($line); my $tmp = [split /:/]; $avg += $tmp->[1]; push @data, $tmp; } $avg = scalar(@data) ? $avg /= @data : 0; my $std = 0; for (@data) { $std += abs($_->[1] - $avg) } $std = scalar(@data) ? $std /= @data : 0; open(OUT, ">pa5c.dat") || die ("Can't open file $!\n"); for (@data) { my $grade; my $dev = ($_->[1] - $avg) / $std; if ($dev >= 1) { $grade = 'A' } elsif ($dev >= (1/3)) { $grade = 'B' } elsif ($dev >= (-1/3)) { $grade = 'C' } elsif ($dev > -1) { $grade = 'D' } else { $grade = 'E' } print OUT join (':', $_->[0], $_->[1], $grade) . "\n"; } close OUT; __END__#pa52.pl
Now if my program runs correctly, my program should assign letter grades to the students.Smith:70 Jones:74 Rider:80 High:82 Billie:68 Smithsonville:76
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jptxs) Re: Filehandles - opening/closing a filehandle
by jptxs (Curate) on Apr 08, 2001 at 20:02 UTC | |
|
Re: Filehandles - opening/closing a filehandle
by rchiav (Deacon) on Apr 08, 2001 at 20:21 UTC | |
|
Re: Filehandles - opening/closing a filehandle
by wardk (Deacon) on Apr 08, 2001 at 20:02 UTC |