aznsj
Newbie level 6
The purpose of below Perl script is to list the elements which are above the average. Unfortunately, I cannot debug it myself, can you help me ?
//////////////////////////
use warnings;
@fred =(1..10);
$sum=&total(@fred);
$ave=&ave(@fred);
@list=&ab_ave(@fred);
print "\@fred is @fred\n";
print "(should be 6 7 8 9 10) \n";
sub total
{my $sum;
foreach (@_)
{$sum +=$_;
}
$sum;
}
sub ave
{my $count=@_;
my $sum=&total(@_);
$sum/$count;
}
sub ab_ave
{my $ave=&ave(@_);
my @list;
foreach(@_)
{if ($_>$ave)
push @list, $_;
}
}
//////////////////////////
use warnings;
@fred =(1..10);
$sum=&total(@fred);
$ave=&ave(@fred);
@list=&ab_ave(@fred);
print "\@fred is @fred\n";
print "(should be 6 7 8 9 10) \n";
sub total
{my $sum;
foreach (@_)
{$sum +=$_;
}
$sum;
}
sub ave
{my $count=@_;
my $sum=&total(@_);
$sum/$count;
}
sub ab_ave
{my $ave=&ave(@_);
my @list;
foreach(@_)
{if ($_>$ave)
push @list, $_;
}
}