convenientstore has asked for the wisdom of the Perl Monks concerning the following question:
I think I understand the .= but not sure of the implication in this.. shouldn't it be just $grades{$student} = $grade ??$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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: first perl example from perl book
by chromatic (Archbishop) on Jan 15, 2008 at 06:25 UTC | |
by convenientstore (Pilgrim) on Jan 15, 2008 at 07:12 UTC | |
by cdarke (Prior) on Jan 15, 2008 at 07:47 UTC | |
by Gangabass (Vicar) on Jan 15, 2008 at 07:46 UTC | |
|
Re: first perl example from perl book
by dwm042 (Priest) on Jan 15, 2008 at 15:30 UTC | |
by convenientstore (Pilgrim) on Jan 15, 2008 at 16:30 UTC |