alunosnotasbimestral
ayes 8.5 6.5 7.0 10.0
andre 7.0 9.0 8.5 8.5
la 9.0 7.0 4.5 7.5
gui 4.5 8.0 8.0 6.0
lu 4.0 4.0 4.0 4.0
-----------------------------------------------------------------------------------------------------------------------------
#!usr/bin/perl
use strict;
use warnings;
my %nomes;
my $media = 0;
my $qnt = 4;
open(IN,'alunosnotasbimestral') or die $!;
while(<IN>){
my($id,@notas) = split(/\t/,$_);
@{$nomes{$id}} = @notas;
}
close(IN);
foreach my $key(keys %nomes){
for(my $i = 0; $i < 4; $i++){
$media += $nomes{$key}[$i];
}
$nomes{$key}[4] = $media/4;
$media = 0;
}
foreach my $key(keys %nomes){
print "\n $key : ";
for(my $i = 0; $i < 5; $i++){
print " $nomes{$key}[$i] ";
}
print"\n";
}
result
$perl blog.pl
ayes : 8.5 6.5 7.0 10.0
8
la : 9.0 7.0 4.5 7.5
7
gui : 4.5 8.0 8.0 6.0
6.625
andre : 7.0 9.0 8.5 8.5
8.25
lu : 4.0 4.0 4.0 4.0
4
0 comentários:
Post a Comment