while going over the first perl code example from "Programming perl" and in attempt to run it w/ strict, I made couple modification.
Strangely, it's complaining that it doesn't see the data that I have provided at the end of the __END__
I have used this before on other program.. but here seem to be an issue
Can someone point out for me what I am doing wrong?
Also, what is the point of doing
$grades{$student} .= $grade . " ";
I think I understand the .= but not sure of the implication in this.. shouldn't it be just
$grades{$student} = $grade ??
#!/usr/bin/perl -w
use strict;
my %grades;
while (<DAT>) {
chomp;
my($student,$grade) = split (" ",$_);
#$grades{$student} .= $grade . " ";
$grades{$student} = $grade;
}
for (sort keys %grades) {
my $scores = 0;
my $total = 0;
my @grades = split(" ", $grades{$_});
for (@grades) {
$total += $_;
$scores++;
}
my $average = $total / $scores;
print "$_: $grades{$_}\tAverage: $average\n";
}
__END__
lee 99
lee 100
kim 90
kim 90
kim 95
kim 100
kim 50
lee 75
:!perl -c ./././perl.score
Name "main::DAT" used only once: possible typo at ./././perl.score lin
+e 7.
./././perl.score syntax OK
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.