fork download
  1. #!/usr/bin/perl
  2. #!/usr/bin/env perl
  3.  
  4. use strict;
  5. use warnings;
  6. use utf8;
  7.  
  8. open(GRADES, "grades.txt") or die "can't open fucking file: $!\n";
  9. while (my $line = <GRADES>) {
  10. (my $student, my $grade) = split(" ", $line);
  11. my $grades{$student} .= $grade . " ";
  12. }
  13.  
  14. foreach my $student (sort keys %grades){
  15. my $scores = 0;
  16. my $total = 0;
  17. my @grades = split(" ", $grades{$student});
  18. foreach my $grade (@grades){
  19. my $total += $grade;
  20. my $scores++;
  21. }
  22. my $average = $total / $scores;
  23. print "$student : $grades{$student} \tMID: $average\n";
  24. }
  25.  
  26.  
Runtime error #stdin #stdout #stderr 0s 6128KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
"my" variable %grades masks earlier declaration in same statement at prog.pl line 14.
syntax error at prog.pl line 11, near "$grades{"
Global symbol "$grade" requires explicit package name at prog.pl line 11.
syntax error at prog.pl line 24, near "}"
Execution of prog.pl aborted due to compilation errors.