in reply to print statement to avoid printing aline more than once
Just put your scores into an array and calculate the average using List::Util sum in a second loop.
use List::Util qw(sum); use strict; use warnings; my %scores; while (<DATA>) { chomp; my @fields = split ','; push @{$scores{$fields[2]}}, $fields[3]; } for my $student (keys %scores) { my $average = sum(@{$scores{$student}}) / @{$scores{$student}}; print "you bad boy, $student, $average\n" if $average < 50; } __DATA__ XY,50,weret,30,reewrw XY,25,weret,30,rerwe yz,45,ferr,55,rwree YZ,90,ferr,55,deert
|
|---|