#!/n/gnu/bin/perl -w

foreach $file (@ARGV) {
    print "Processing $file...";
    $hashref = notas($file);
    foreach $key (keys %{$hashref}) {
	# $key e' o nome do aluno
	$soma_notas{$key} += $hashref->{$key};
	# $nnnotas e' o numero de notas que ele tem
	$nnotas{$key} ++;
    }
    print "  File $file done\n";
}

foreach $key (keys %nnotas) {
    print "$key $nnotas{$key} ";
    printf "%4.1f\n", $soma_notas{$key}/$nnotas{$key};
}

sub notas {
    my $FILE = shift;
    my $grade;
    my $name;
    my %hash = ();
    open FILE,$FILE or return {};
    while(<FILE>) {
	/width/ && /(\d+\.\d)/ && do {
	    print "   grade $1";
	    $grade = $1;
	    next;
	};

	/width/ && /\>(\d\d\d\d\d\d)\</ && do {
	    print " name $1\n";
	    $name = $1;
	    $hash{$name} = $grade;
	    next;
	};
    }
    return \%hash;
}
